String url = ""; CloseableHttpClient httpClient = HttpClientBuilder.create().build(); HttpPost httpPost = new HttpPost(url); StringEntity stringEntity = new StringEntity(JSON.toJSONString(data), "UTF-8"); httpPost.setEntity(stringEntity); httpPost.setHeader("Content-Type", "application/json;charset=utf8"); CloseableHttpResponse response = null; try { // 由客户端执行(发送)Post请求 response = httpClient.execute(httpPost); // 从响应模型中获取响应实体 HttpEntity responseEntity = response.getEntity(); if (responseEntity != null) { log.info("响应内容:" + EntityUtils.toString(responseEntity)); } } catch (IOException e) { e.printStackTrace(); } finally { try { // 释放资源 if (httpClient != null) { httpClient.close(); } if (response != null) { response.close(); } } catch (IOException e) { e.printStackTrace(); } }