直接看代码
final String CONTENT_TYPE_TEXT_JSON = "text/json";
HttpClient client = HttpClientBuilder.create().build();
String url = "url";
String js = "{\"id\":\" " + id + " \"}";
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("");
httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
StringEntity se = null;
try {
se = new StringEntity(js);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
se.setContentType(CONTENT_TYPE_TEXT_JSON);
httpPost.setEntity(se);
HttpResponse response2 = null;
String s2 = null;
try {
response2 = client.execute(httpPost);
HttpEntity entity2 = null;
entity2 = response2.getEntity();
s2 = EntityUtils.toString(entity2, "UTF-8");
} catch (IOException e) {
e.printStackTrace();
}
return ResultUtil.successToObject(JSONObject.parseObject(s2));