可以逃避破坏我的http GET请求?

时间:2015-02-15 09:33:34

标签: java http url escaping webresource

我尝试触发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

1 个答案:

答案 0 :(得分:0)

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

   .queryParam("from", "x%3A34.78104114532471 y%3A31.243920719573723")
   .queryParam("to", "x%3A34.77901339530945 y%3A31.242416368424312")