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