简体   繁体   English

使用WebTarget时指定原始查询字符串

[英]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.

相关问题 字符串中的WebTarget - WebTarget from String 在使用 Javax webtarget 客户端发送 HTTPS 请求时,如何避免对包含“:[”的查询参数进行编码? - In sending HTTPS request using Javax webtarget client, how to avoid encoding of query params that contain ":["? 使用toplink基本查询提示时指定查询超时 - specify query timeout when using toplink essential query hint 使用本机SQL查询时如何指定数据类型? - How to specify data type when using native SQL query? 如何避免转义 WebTarget 查询参数? - How can I avoid escaping a WebTarget query parameter? WebTarget 类型中的方法 request(String...) 不适用于参数 (MediaType) - The method request(String...) in the type WebTarget is not applicable for the arguments (MediaType) 使用与WebTarget DELETE链接或取消链接的queryParam会产生不同的结果 - Using queryParam linked or unlinked with WebTarget DELETE produces different results 为什么execSQL接受Object []和原始查询字符串[] - Why execSQL accepts Object[] and raw Query String[] 原始查询无法将BLOB转换为用于选择String []列的字符串 - Raw Query is unable to convert BLOB to string for selecting column of String[] 如何指定一个字段,以便在查询时使用字段的Joda LocalDate或LocalDateTime值将其映射到同一列? - How to specify a field, so that when we query, using Joda LocalDate or LocalDateTime value for the field, it is mapped to same column?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM