0

I try to trigger an http GET request

It should be as follows:

https://www.my_service.com/myRequest?from=x%3A34.78104114532471+y%3A31.243920719573723&to=x%3A34.77901339530945+y%3A31.242416368424312&

I wrote this code

            webResource.accept("application/json");

            ClientResponse response = webResource.path("myRequest")
                    .queryParam("from", "x%3A34.78104114532471+y%3A31.243920719573723")
                    .queryParam("to", "x%3A34.77901339530945+y%3A31.242416368424312")
.accept(MediaType.APPLICATION_JSON_TYPE)
                    .get(ClientResponse.class);

            if (response.getStatus() != 200) {
                throw new RuntimeException("Failed : HTTP error code : "
                        + response.getStatus());
            }

which generates this url:

https://www.my_service.com/myRequest?from=x%3A34.78104114532471+y%3A31.243920719573723&to=x%3A34.77901339530945+y%3A31.242416368424312&

but this returns 404 error.

I have tried the two urls in the browser. The only difference is + replaced by %2B

+ works for me but %2B doesn't.

how can i make the code not replace + with %2B?

Elad Benda
  • 35,076
  • 87
  • 265
  • 471

1 Answers1

0

Strangely I had to replace + with space:

   .queryParam("from", "x%3A34.78104114532471 y%3A31.243920719573723")
   .queryParam("to", "x%3A34.77901339530945 y%3A31.242416368424312")
Elad Benda
  • 35,076
  • 87
  • 265
  • 471
  • Makes perfect sense, doesn't it? You're using an API which does the necessary escaping internally. Maybe you just don't know the rules---`+` is the escape char for space in URLs. – Marko Topolnik Feb 15 '15 at 10:16
  • 1
    For that matter, I suggest you use the plain `:` character instead of `%3A` and get that escaped internally as well. Would make your code much easier on the eye. – Marko Topolnik Feb 15 '15 at 10:20