Url encoding issue with Jersey Client

℡╲_俬逩灬. 提交于 2019-12-23 14:59:13

问题


I need to make a service call such as this: http://myservice.com/path?var1=value1&var2=value2

The issue I have is value1 and value2 ends up getting encoded, and this makes the service call fail. For example, value1 is something like "a=b&b=c;2&&="... it contains special characters, basically.

I am guessing that this is an issue for the service to fix - to properly handle decoding encoded characters, which I do not think it is currently doing.

Here is a sample of how I am making these requests:

WebTarget target = client.target("http://test.com")
    .path("path1")
    .queryParam("var1", var1);
Builder builder = target.request();
...

What's puzzling to me is that if I make the same request just using Chrome, everything works. So that makes me to believe that I should have some way with the Jersey API of "disabling" the encoding.


回答1:


Only way I have found so far to use "raw" Url is to use URI. So call like this

URI uri = URI.create("http://localhost/~Common~0#/edit?vadf&&sfs&&fdsfd=fs&fsd");
WebTarget target = client.target(uri);

You get request url

1 > GET http://localhost/~Common~0#/edit?vadf&&sfs&&fdsfd=fs&fsd

Everything else I tried resulted in encoding special characters.



来源:https://stackoverflow.com/questions/35260836/url-encoding-issue-with-jersey-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!