1

From Java code I want to call a webservice like this:

"http://example.com/mytarget?firstParam=xxx&currency=EUR"

But no matter what I do. As soon as I compose a String with "&currency=" in it, it gets replaced by "¤cy=" instantly, which the webservice doesn't like and responds with an error.

To illustrate, here is a small code snipet I use:

String uri = "http://example.com?test=1&currency=EUR";
HttpGet request = new HttpGet(uri); //string got replaced already!
request.addHeader("content-type", "application/json");
HttpResponse result = httpClient.execute(request);
String json = EntityUtils.toString(result.getEntity(), "UTF-8");

The above code makes a call to:"http://example.com?test=1¤cy=EUR"

Similar Question, no answer: https://stackoverflow.com/questions/29890388/how-to-get-curren-to-display-literally-not-as-an-html-entity-in-Java

Any ideas? Or is there a "proper" way to call a webservice from Java code that avoids this problem?

Community
  • 1
  • 1
Jimmy Gee
  • 27
  • 5
  • HttpGet must be doing that. Maybe HttpGet provides a different mechanism to add query params.. – Juned Ahsan Jun 24 '15 at 22:56
  • You could use `currency` as first parameter. – Eng.Fouad Jun 24 '15 at 22:59
  • Not sure this is a clear cut duplicate, because the example he's provided should not require any encoding to work. @OP: For what it's worth, I tested your example and checked with Fiddler to see what URL was generated, and it looked fine for me. Are you sure the problem is not with the service itself? – sstan Jun 24 '15 at 23:28
  • 2
    It sounds like you're saying `System.out.println("&curren");` does not output "`&curren`". But it does. – djeikyb Jun 24 '15 at 23:29
  • The "duplicate" doesn't seem to be related at all. What is HttpGet? How are you demonstrating that the string has been replaced? – Samuel Edwin Ward Jun 24 '15 at 23:33
  • 1
    @OP: Where, in the chain of events, do you first notice the URL changing as you describe? Do you see it in the java code? Do you intercept the request and notice it there? Do you notice it on the service side? – sstan Jun 25 '15 at 13:03
  • @djeikyb Thanks for the hint with the `System.out.println("&curren");` I thought I had checked that but I didn.t... Turns out that it's only a display problem in the online log files I was checking. Problem solved. Thank you all for your help anyway! And sorry ;) – Jimmy Gee Jun 26 '15 at 15:45

0 Answers0