我使用Jersey javax.ws.rs
来调用url
的java:
...
String eoEndPoint = "http://exemple.com/";
String url = "offres/test/2015-01-07?return=2015-01-09&withThac=false";
ClientConfig clientConfig = new ClientConfig();
Client client = ClientBuilder.newClient(clientConfig).register(new Authenticator(user, password));
WebTarget webTarget;
webTarget = client.target(eoEndPoint)
.path(url);
Invocation.Builder invocationBuider = webTarget.request();
invocationBuider.accept(mediaType);
Offers response = invocationBuider.get(Offers.class);
return response;
...
当我执行此代码时,我有一个HTTP 404 Not Found
为什么invocationBuider.get(Offers.class);
将我的网址http://exemple.com/offres/test/2015-01-07?return=2015-01-09&withThac=false
转换为http://exemple.com/offres/test/2015-01-07%3Dreturn=2015-01-09&withThac=false
?
转换为%3D
为什么。?
答案 0 :(得分:1)
您正在将查询参数传递给需要URI的path()
方法,因此任何特殊字符(例如?
,=
)都会被转义。您需要使用专用方法queryParam()
来提供查询参数。
替换
.path(url); // "offres/test/2015-01-07?return=2015-01-09&withThac=false";
与
.path("offres/test/2015-01-07")
.queryParam("return", "2015-01-09")
.queryParam("withThac", "false")