[英]Specify raw query string when using WebTarget
I'm working with a large existing project, which utilises javax.ws.rs.client.WebTarget
to talk to RESTful API. 我正在处理一个大型现有项目,该项目利用
javax.ws.rs.client.WebTarget
与RESTful API进行通信。 The API is developed by a third party and I have no control over it. 该API是由第三方开发的,我对此无能为力。 I need to make a request in the following format:
我需要以以下格式发出请求:
https://end.point.url/endpoint/id?data
Unfortunately, I can't figure out how to specify such request using WebTarget
. 不幸的是,我不知道如何使用
WebTarget
来指定这样的请求。 I tried using path("endpoint/id?data")
, but this gets converted into endpoint/id%3Fdata
and I get 404 back. 我尝试使用
path("endpoint/id?data")
,但这被转换为endpoint/id%3Fdata
,我得到404。 I tried using queryParam
specifying empty value, which gets me endpoint/id?data=
- which results in error required parameter data
missing . 我尝试使用
queryParam
指定空值,这使我得到了endpoint/id?data=
-这导致错误的必需参数data
丢失 。
What other option is there? 还有什么其他选择? Replacing WebTarget with something else isn't feasible, as it is all over the large project.
用其他东西替换WebTarget是不可行的,因为这遍及整个大型项目。
First, related question: Url encoding issue with Jersey Client 首先,相关问题: Jersey客户端的网址编码问题
After quite a bit of research, it seems that the only way to do it is to specify the entire uri when the WebTarget is created, like so: 经过大量研究,似乎唯一的方法是在创建WebTarget时指定整个uri,如下所示:
Client client = ClientBuilder.newClient().register(authFeature);
WebTarget webTarget = client.target("https://end.point.url/endpoint/id?data")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.