【发布时间】:2015-10-29 12:24:16
【问题描述】:
这是我的代码:
HttpClient client = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(postUrl);
httpPost.setHeader("Content-Type", MediaType.APPLICATION_JSON);
StringEntity bodyEntity = new StringEntity("{\"name\":\"hello\"}");
bodyEntity.setContentType(MediaType.APPLICATION_JSON);
httpPost.setEntity(bodyEntity);
HttpResponse response = client.execute(httpPost);
String responseString = new BasicResponseHandler().handleResponse(response);
System.out.println(responseString);
我不断收到错误unsupported content type 虽然我的网络服务只需要json,但我检查了httpPost 内容类型,它始终是plain text,请问为什么它没有更改为JSON?
【问题讨论】: