我想对http://www.cleartrip.com/places/hotels/info/41748
进行一次宁静的网络服务调用如何在请求字符串中形成动态属性?以下是我尝试过但不起作用的内容:
Client client = ClientBuilder.newClient();
client.property("hotelnr", 41748);
//works not (HTTP 404 Not Found):
client.target("http://www.cleartrip.com/places/hotels/info/{hotelnr}").request(MediaType.APPLICATION_XML).get();
//works:
client.target("http://www.cleartrip.com/places/hotels/info/41748").request(MediaType.APPLICATION_XML).get();
答案 0 :(得分:4)
查看:http://docs.oracle.com/javaee/7/tutorial/doc/jaxrs-client001.htm#sthref1397
您可以执行以下操作:
WebTarget myResource = client.target("http://example.com/webapi/read")
.path("{userName}");
Response response = myResource.queryParam("userName", "janedoe")
.request(...)
.get();