From 849c3bfad21a3821f303413f82cda2d8d4d27733 Mon Sep 17 00:00:00 2001
From: dongyukun <1208714201@qq.com>
Date: 星期二, 05 十一月 2024 18:41:31 +0800
Subject: [PATCH] tag查当前值

---
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/utils/HttpRequest.java |   42 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/utils/HttpRequest.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/utils/HttpRequest.java
index e3816d5..c0f580d 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/utils/HttpRequest.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/utils/HttpRequest.java
@@ -1,5 +1,10 @@
 package com.iailab.module.data.common.utils;
 
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.util.EntityUtils;
 import org.springframework.util.CollectionUtils;
 
 import java.io.BufferedReader;
@@ -137,6 +142,7 @@
             // 打开和URL之间的连接
             URLConnection conn = realUrl.openConnection();
             // 设置通用的请求属性
+            conn.setRequestProperty("content-type", "application/json");
             conn.setRequestProperty("accept", "*/*");
             conn.setRequestProperty("connection", "Keep-Alive");
             conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
@@ -232,4 +238,40 @@
         }
         return result;
     }
+
+    /**
+     *
+     * @param url
+     * @param json
+     * @param charset
+     * @param token
+     * @return
+     */
+    public static String doPost(String url, String json, String charset, String token) {
+        org.apache.http.client.HttpClient httpClient = null;
+        HttpPost httpPost = null;
+        String result = null;
+        try {
+            httpClient = new SSLClient();
+            httpPost = new HttpPost(url);
+            //设置参数
+            httpPost.addHeader("Accept", "application/json");
+            httpPost.addHeader("Content-Type", "application/json;charset=UTF-8");
+            httpPost.addHeader("token", token);
+            StringEntity stringEntity = new StringEntity(json);
+            stringEntity.setContentEncoding("UTF-8");
+            stringEntity.setContentType("application/json");
+            httpPost.setEntity(stringEntity);
+            HttpResponse response = httpClient.execute(httpPost);
+            if (response != null) {
+                HttpEntity resEntity = response.getEntity();
+                if (resEntity != null) {
+                    result = EntityUtils.toString(resEntity, charset);
+                }
+            }
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+        return result;
+    }
 }

--
Gitblit v1.9.3