简体   繁体   English

Jersey客户端将内容类型标题设置为text / plain

[英]Jersey Client set content-type header as text/plain

Using jersey client sending HTTP request. 使用泽西客户端发送HTTP请求。 Content-Type header is automatically set as "application/json" (as a nature), but i want to changing "content-type" header with "text/plain" regardless of any specification, standards etc. Jersey version is 2.4.1. Content-Type标头自动设置为“ application / json”(本质上),但是我想用“ text / plain”更改“ content-type”标头,而不管任何规范,标准等如何。Jersey版本是2.4.1 。

Code

String target = "http://192.168.1.2:10000";
String path = "test3";

Client c = ClientBuilder.newClient ();
WebTarget target = c.target (target).path (path);

Entity<SubscriberBean> json = Entity.json (subscriber);
Builder request = target.request ();

String response = request.post(json, String.class);

Request 请求

POST /test3 HTTP/1.1
Accept: text/html
Content-Type: application/json
User-Agent: Jersey/2.4.1 (HttpUrlConnection 1.6.0_17)
Host: 192.168.1.2:10000
Connection: keep-alive
Content-Length: 278

///**** Some json data ***///

instead of 代替

request.post(json, String.class);

try to use 尝试使用

request.type(MediaType.TEXT_PLAIN).post(json, String.class);

Entity.text(entityData)使用Entity.text(entityData)Entity.entity(entityData, mediaType)方法代替Entity.json()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jersey:阅读内容类型:简单/文本响应为XML - Jersey: Reading Content-Type:plain/text response as XML 使用EWS java API将Content-Type设置为text / plain - Set Content-Type as text/plain using EWS java API 无法从Elastic 6.0获取数据:“错误”:“不支持Content-Type标头[文本/纯文本]”,“状态”:406 - Cannot get data from Elastic 6.0: “error”:”Content-Type header [text/plain] is not supported”,”status”:406 使用Jersey客户端下载文件时内容为空 - Empty content-type while downloading file with Jersey client Jersey:根据文件扩展名或InputStream设置响应内容类型? - Jersey: Set response content-type based on file extension or InputStream? Spring MVC 3返回内容类型:text / plain - Spring MVC 3 Return Content-Type: text/plain org.jboss.resteasy.client.ClientResponseFailure:无法找到内容类型为文本/纯文本且类型为类java.lang.String的MessageBodyReader - org.jboss.resteasy.client.ClientResponseFailure: Unable to find a MessageBodyReader of content-type text/plain and type class java.lang.String Firefox甚至尝试使用Content-Type解析XML:text / plain - Firefox tries to parse XML even with Content-Type: text/plain Spring Data Rest自定义控制器,带内容类型:“text / plain” - Spring Data Rest Custom Controller With with content-Type:“text/plain” REST客户端的Content-Type标头引发UnsupportedOperationException - REST client Content-Type header throws UnsupportedOperationException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM