/**
* 发送json请求
*
* @param jsonBody
* @param URL
* @return
*/
public static String doPost(org.json.JSONObject jsonBody, String URL) throws IOException {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(URL);
post.addHeader("Content-type", "application/json; charset=utf-8");
post.setEntity(new StringEntity(jsonBody.toString(), Charset.forName("UTF-8")));
HttpResponse response = client.execute(post);
HttpEntity httpEntity = response.getEntity();
String resultString = EntityUtils.toString(response.getEntity(), "UTF-8");
return resultString;
}
依赖
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
</dependency>