From 66e0f592475cebf0511be54f71217be5ba4245c8 Mon Sep 17 00:00:00 2001
From: liuhaonan <konodioda2333@vip.qq.com>
Date: 星期三, 09 二月 2022 14:11:25 +0800
Subject: [PATCH] 功能完善

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/utils/VnnoxRequestUtil.java |   68 ++++++++++++++++++++++++---------
 1 files changed, 49 insertions(+), 19 deletions(-)

diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/utils/VnnoxRequestUtil.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/utils/VnnoxRequestUtil.java
index 3b9e37a..3a34f21 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/utils/VnnoxRequestUtil.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/utils/VnnoxRequestUtil.java
@@ -2,7 +2,9 @@
 
 import com.sandu.ximon.admin.utils.request.CommonHeader;
 import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
 import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.utils.URIBuilder;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.impl.client.CloseableHttpClient;
@@ -12,6 +14,10 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
+import java.util.Map;
 
 public class VnnoxRequestUtil {
 
@@ -35,29 +41,53 @@
         return result;
     }
 
-    public static String GetWithHeader (String url, String params, CommonHeader header) {
-        CloseableHttpClient client = HttpClients.createDefault();
-        HttpGet get = new HttpGet(url);
-        for(String key: header.keySet()) {
-            get.setHeader(key, header.get(key));
-        }
-        String result = null;
-        try {
-            StringEntity s = new StringEntity(params, UTF8);
-            s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
-                    "application/json"));
-            HttpResponse httpResponse = client.execute(get);
-            InputStream inStream = httpResponse.getEntity().getContent();
+//    public static String GetWithHeader (String url, String params, CommonHeader header) {
+//        CloseableHttpClient client = HttpClients.createDefault();
+//        HttpGet get = new HttpGet(url);
+//        for(String key: header.keySet()) {
+//            get.setHeader(key, header.get(key));
+//        }
+//        String result = null;
+//        try {
+//            StringEntity s = new StringEntity(params, UTF8);
+//            s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
+//                    "application/json"));
+//            HttpResponse httpResponse = client.execute(get);
+//            InputStream inStream = httpResponse.getEntity().getContent();
+//
+//            result = streamToString(inStream, UTF8);
+//
+//            inStream.close();
+//        } catch (Exception e) {
+//            return null;
+//        }
+//        return result;
+//    }
+public static String GetWithHeader (String url, List<NameValuePair> urlParameters, Map<String, String> header) throws URISyntaxException {
 
-            result = streamToString(inStream, UTF8);
 
-            inStream.close();
-        } catch (Exception e) {
-            return null;
-        }
-        return result;
+    URI finalURI = new URIBuilder(url).setParameters(urlParameters).build();
+    CloseableHttpClient client = HttpClients.createDefault();
+    HttpGet get = new HttpGet(finalURI);
+    for(String key: header.keySet()) {
+        get.setHeader(key, header.get(key));
     }
+    String result = null;
+    try {
+//            StringEntity s = new StringEntity(params, UTF8);
+//            s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
+//                    "application/json"));
+        HttpResponse httpResponse = client.execute(get);
+        InputStream inStream = httpResponse.getEntity().getContent();
 
+        result = streamToString(inStream, UTF8);
+
+        inStream.close();
+    } catch (Exception e) {
+        return null;
+    }
+    return result;
+}
 
 
 

--
Gitblit v1.9.3