From ad57a3e46fe82d05ff05d92a5ca931fbc4e71cac Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Sat, 12 Nov 2022 15:39:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=81=AB=E7=82=B9=E8=BD=AC=E5=8F=91-=E4=B9=B1?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/service/impl/FirePointServiceImpl.java | 2 +- .../java/com/xkrs/utils/HttpClientUtils.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java index 14c4714..bb9fc6c 100644 --- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java @@ -510,7 +510,7 @@ public class FirePointServiceImpl implements FirePointService { private void forwardPoint(FirePointEntity firePointEntity) { try { String url = "http://121.36.229.60:6811/insertfirepointchannelThree"; - HttpClientUtils.sendHttpPost(url, new ObjectMapper().writeValueAsString(firePointEntity)); + HttpClientUtils.sendHttpPostTextPlain(url, new ObjectMapper().writeValueAsString(firePointEntity)); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/com/xkrs/utils/HttpClientUtils.java b/src/main/java/com/xkrs/utils/HttpClientUtils.java index 2d5ac2b..bc45351 100644 --- a/src/main/java/com/xkrs/utils/HttpClientUtils.java +++ b/src/main/java/com/xkrs/utils/HttpClientUtils.java @@ -75,6 +75,23 @@ public class HttpClientUtils { return doPost(httpClient, url, params); } + public static String sendHttpPostTextPlain(String url, String params) throws Exception { + CloseableHttpClient httpClient = HttpClients.createDefault(); + return doPostTextPlain(httpClient, url, params); + } + + private static String doPostTextPlain(CloseableHttpClient httpClient, String url, String params) throws Exception { + log.info("Post请求url:{}", url); + log.info("Post请求params:{}", params); + HttpPost httpPost = new HttpPost(url); + httpPost.addHeader("Content-Type", "application/json; charset=utf-8"); + StringEntity requestEntity = new StringEntity(params, "UTF-8"); + requestEntity.setContentType("text/plain"); + requestEntity.setContentEncoding("UTF-8"); + httpPost.setEntity(requestEntity); + return execute(httpClient, httpPost); + } + /** * 发送https+post请求 *