Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

tFileFetch HTTP header

Hi,
I need to get information through an HTTP GET request.
To do so, I use a tFileFetch component.
But I need to put an 'Authorization' token into the HTTP header...
Is there any way to do this ?
Thanks a lot.
Labels (2)
1 Solution

Accepted Solutions
aeugen
Contributor
Contributor

I used shong's advice, and for me it works fine.
My auth scheme a little bit more complicated:
local PC -> NTLM Proxy auth -> HTTP Basic auth -> HTTP data

View solution in original post

6 Replies
Anonymous
Not applicable
Author

Hello
On the 'Advanced settings' tab of tFileFetch, there is a 'need authentication' option.
Best regards
shong
Anonymous
Not applicable
Author

Thanks for your answer.
But the authentication mechanism in Talend deals with login/password.
My 'Authorization' HTTP header data is a big string, not a user/password couple.
It should looks like : Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== ... in the HTTP header...
I've tried to put my string into each of those fields but it doesn't work...
Is this authentication information will end into the 'Authorization' field of the HTTP header ?
_AnonymousUser
Specialist III
Specialist III

I'm dealing with the exact same issue. Anybody resolve this? I need to get the Authorization variable into the Get header.
aeugen
Contributor
Contributor

I used shong's advice, and for me it works fine.
My auth scheme a little bit more complicated:
local PC -> NTLM Proxy auth -> HTTP Basic auth -> HTTP data
_AnonymousUser
Specialist III
Specialist III

Probably what you have is base64 encoded... so from your example the decode command is
$ echo QWxhZGRpbjpvcGVuIHNlc2FtZQ== | mmencode -u
Aladdin 0683p000009MA5A.pngpen sesame
So you login name is Aladdin and your password is "open sesame"
Have fun.
Anonymous
Not applicable
Author

I had a heck of a time getting things to work how it was described here so instead I wrote some code in a tJava component and looks like: (hopefully someone else would find this helpful)
//conn.getResponseCode() returns -1 when the making multiple calls in a loop so you need to make sure that the streams are closed and the connection is fully closed
System.setProperty("http.keepAlive", "false");

java.net.URL url = new java.net.URL(context.wsdl_url);

java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("PUT");//you can specify what type of request you want to do here.... PUT, GET, POST... etc..
conn.setRequestProperty("Content-Type", "application/json");

String username = context.username;
String password = context.password;

sun.misc.BASE64Encoder enc = new sun.misc.BASE64Encoder();
String userpassword = username + ":" + password;
String encodedAuthorization = enc.encode( userpassword.getBytes() );
conn.setRequestProperty("Authorization", "Basic "+encodedAuthorization);
conn.setAllowUserInteraction(true);

String input = "{\"order_note\": \"Order downloaded.\",\"email_note\":Something here}";//payload to send to the server...


java.io.OutputStream os = conn.getOutputStream();
os.write(input.getBytes());
os.flush();
os.close();

if (conn.getResponseCode() != java.net.HttpURLConnection.HTTP_NO_CONTENT) {
context.log += "\r\n"+currentTS+" Client:"+context.cust_code+" Order update failed. "+conn.getResponseCode()+" and message: "+conn.getResponseMessage();
throw new RuntimeException("Orders might have been downloaded but failed to update order status at store. Failed : HTTP error code : "
+ conn.getResponseCode());
}



java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(
(conn.getInputStream())));

String output;
System.out.println("Output from Server .... \n");

while ((output = br.readLine()) != null) {
System.out.println(output);
}

conn.getInputStream().close();//be sure to close the stream OR in the while loop above make sure you read ALL the contents from the stream BEFORE closing it

conn.disconnect();
System.out.println("disconnected...");