• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Issue in Calling webservice with special character in hostname using HTTP GET

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Issue in Calling webservice with special character in hostname using HTTP GET method,

When i execute it using java code i am getting 401 unauthorized. But the same is working successfully in postman

Below is the code

String appKey = "b980cf5d9fcce29da2c51afe73334349696cb7c031434348e";
String column = URLEncoder.encode(":", "UTF-8");
String atsymbol =  URLEncoder.encode("@", "UTF-8");

String url = "https://"+appKey+column+"X"+atsymbol+"app.listen360.com/organizations/628956/reviews.xml";
GetMethod httpget = new GetMethod(url);
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new NameValuePair("per_page", "20"));
nvps.add(new NameValuePair("order", "asc"));
httpget.setQueryString(nvps.toArray(new NameValuePair[nvps.size()]));

HttpClient httpclient = new HttpClient();
try {
httpclient.executeMethod(httpget);
if (httpget.getStatusLine().getStatusCode() == 200) {
String responseJson = httpget.getResponseBodyAsString();
System.out.println(responseJson);


}
} catch (IOException e) {
//logError(e);
}
 
Saloon Keeper
Posts: 7631
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Two things to try :

Remove that URL encoding - it does not do anything for the characters you're using it for.

Don't ignore the exception - log the full stacktrace to where you will see it.
 
Marshal
Posts: 79701
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch
 
Sheriff
Posts: 22801
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The user info should contain a literal : and @, not UTF encoded ones. So your URL should simply be https://b980cf5d9fcce29da2c51afe73334349696cb7c031434348e:X@app.listen360.com/organizations/628956/reviews.xml, not the encoded https://b980cf5d9fcce29da2c51afe73334349696cb7c031434348e%3AX%40app.listen360.com/organizations/628956/reviews.xml.

So Tim, it actually does encode the : and @ (to %3A and %40 respectively); the problem is that it shouldn't in this case.
 
Shameer Ammunnikutty
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried to call the  RESTAPI with out using URL Encoder and the problem is the httpget object host variable become https://app.listen.com instead of


The user info should contain a literal : and @, not UTF encoded ones. So your URL should simply be https://b980cf5d9fcce29da2c51afe73334349696cb7c031434348e:X@app.listen360.com/
 
Rob Spoor
Sheriff
Posts: 22801
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That would be the correct value for the host. The user info is not part of the host itself, instead it will be used as part of authentication (probably the Authorization header).
 
You had your fun. Now it's time to go to jail. Thanks for your help tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic