使用澤西客戶端發送HTTP請求。 Content-Type頭自動設置爲「application/json」(作爲一種本質),但是我想用「text/plain」改變「content-type」頭,而不管任何規範,標準等。Jersey版本是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 ***///