jersey 2.22:如何从webtarget检索url(带有queryparams)?

ibps3vxo  于 2021-07-03  发布在  Java
关注(0)|答案(1)|浏览(309)

假设:
WebTarget target = client.target("http://www.someurl.com"); target.queryParam("id", "1").request().post(); 当一个请求在该目标上完成时,我如何获得http://www.someurl.com?id=1 使用jersey api?

8ftvxx2r

8ftvxx2r1#

问题是,如果你看javadoc WebTarget ,您将看到大多数方法调用 WebTarget 返回新的 WebTarget 示例。所以当你这么做的时候

WebTarget target = client.target("http://www.someurl.com");
target.queryParam("id", "1").request().post();
System.out.println(target.getUri());

这个 target 示例与添加查询参数的示例不同。所以你要么

WebTarget target = client.target("http://www.someurl.com");
WebTarget newTarget = target.queryParam("id", "1");
newTarget.request().post();
System.out.println(newTarget.getUri());

WebTarget target = client.target("http://www.someurl.com").queryParam("id", "1");
target.request().post();
System.out.println(target.getUri());

相关问题