Jersey URL无效加密

时间:2015-01-06 10:42:47

标签: java jax-rs

我使用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为什么。?

1 个答案:

答案 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")