Jersey Client的网址编码问题 [英] Url encoding issue with Jersey Client
问题描述
我需要拨打这样的服务电话: http://myservice.com/path?var1=value1&var2=value2
I need to make a service call such as this: http://myservice.com/path?var1=value1&var2=value2
我遇到的问题是value1和value2最终被编码,这使服务调用失败.例如,value1类似于"a = b& b = c; 2&& ="...,它基本上包含特殊字符.
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();
...
让我感到困惑的是,如果我仅使用Chrome发出相同的请求,一切都会正常.因此,使我相信,Jersey API应该可以禁用"编码.
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.
推荐答案
到目前为止,我发现使用原始" URL的唯一方法就是使用URI. 所以这样叫
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);
您获得请求网址
1 > GET http://localhost/~Common~0#/edit?vadf&&sfs&&fdsfd=fs&fsd
我尝试的所有其他操作都导致对特殊字符进行编码.
Everything else I tried resulted in encoding special characters.
这篇关于Jersey Client的网址编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!