0

我尝试触发一个 http GET 请求

它应该如下:

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

我写了这段代码

            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());
            }

生成此网址:

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

但这会返回 404 错误。

我已经在浏览器中尝试了这两个网址。唯一的区别被+替换为%2B

+对我有用,但%2B没有。

我怎样才能使代码不替换+%2B

4

1 回答 1

0

奇怪的是我不得不用空格替换 +:

   .queryParam("from", "x%3A34.78104114532471 y%3A31.243920719573723")
   .queryParam("to", "x%3A34.77901339530945 y%3A31.242416368424312")
于 2015-02-15T10:00:13.410 回答