Getting json response from url.

One Star

Getting json response from url.

Hi all,
I am trying to get a json response by connecting to a url. Using tJson with URL selected yields a 401 error. Using tRest yields a 401 error as well. However the exact same url string returns me the correct json response in both curl and through my web browser. Not sure what else to try.
Here is the format of the URL I have used:

Any help would be greatly appreciated.
One Star

Re: Getting json response from url.

You may have a problem with escape chars ( / ).
One Star

Re: Getting json response from url.

Thanks saburo for the idea.
I did use tFilefetch with this string "" and selecting Need Authentication in the advanced field worked. Which solves the problem of getting json but does not solve the problem of uploading a json file.
I tried tRest does not have the Need Authentication and doing "http://userSmiley" gives me a 401. In tRest I can specify what I send back in the http body but it won't authenticate..

I did try escaping the slashes and same thing. If it was an escape issue would forward slashes still cause it???
One Star

Re: Getting json response from url.

I found weird results with forward and backslashes, never really figured out the exact rule.
Something is happening sometimes because forward slashes are converted into backslashes for cross system compatibility (I guess).
Anyhow, it's not your case since with the same url you managed to get the json, plus 401 is specific to authentication.
REST authentication seems to be a bit more complex than sending usernameSmiley Tongueassword@
see here
and here :
I never used rests, so I cannot help with this one, but based on what I saw in the links, it seems you need to setup specific authentication headers which will contain username and password in base64 encoding...
If the component is not designed to do that... well, it may require a bit of work to extend it for that purpose.
One Star

Re: Getting json response from url.

I have been trying to set the http headers but I don't really know what to put there and the RFC 2617 which explained it left me a little bit more confused. The base64 encoding is not a problem because I already have the string encoded.
In the tRest component I have tried:
URL : ""
name value
"Authorization" "Basic encodedUserName:encodedPassword" -> I know these are the right credentials because copy paste onto browser returns json string as well as doing it through curl.
Http Body:
But I get a 401. Does any one know/understand how to pass the credentials in an HTTP header?
By the way thank you for taking the time to help me out I really appreciate it.
One Star

Re: Getting json response from url.

I think I have exhausted other options.
So to write back a message via REST architecture I used the tJava component with the following code in it:
try { url = new"");//the 1 is the product id conn = ( url.openConnection();
conn.setRequestProperty("Content-Type", "application/json");

String username = "someUser";
String password = "somePassword";

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

String input = "{\"available\":\"14\",\"price\": \"14.99\"}"; os = conn.getOutputStream();
/*if (conn.getResponseCode() != {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());

*/ br = new

String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {

catch (IOException e) {



I hope someone finds this useful. Currently I don't have the time nor the know-how to extend the tRest component to make it work with credentials. But hopefully higher powers can.