【发布时间】:2014-04-16 06:21:33
【问题描述】:
使用 jersey 客户端发送 HTTP 请求。 Content-Type 标头自动设置为“application/json”(作为一种性质),但我想用“text/plain”更改“content-type”标头,不管任何规范、标准等。泽西版本是 2.4.1 .
代码
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);
请求
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 ***///
【问题讨论】: