From 9d3d08ba960fc739498b0648d57eaf2c50a40fd1 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 17 六月 2020 19:17:54 +0800
Subject: [PATCH] '登录'

---
 WindowsFormsApp1/utils/HttpUtil.cs |   35 ++++++++++++++++++++++++++++++++++-
 1 files changed, 34 insertions(+), 1 deletions(-)

diff --git a/WindowsFormsApp1/utils/HttpUtil.cs b/WindowsFormsApp1/utils/HttpUtil.cs
index 5fd1c71..fd7764e 100644
--- a/WindowsFormsApp1/utils/HttpUtil.cs
+++ b/WindowsFormsApp1/utils/HttpUtil.cs
@@ -11,6 +11,7 @@
 {
     class HttpUtil
     {
+        static CookieContainer cookieContainer = new CookieContainer();
         //Get缃戠粶璇锋眰
         public static string HttpGet(String url, Dictionary<String,String> headerMap) {
             string retString = string.Empty;
@@ -39,11 +40,31 @@
             return retString;
         }
 
+
+        public static Stream HttpGetImage(String url)
+        {
+            string retString = string.Empty;
+
+            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
+            request.CookieContainer = cookieContainer;
+            request.Method = "GET";
+            request.Timeout = 60000;
+            //璁剧疆浠g悊
+            WebProxy proxy = new WebProxy();
+            proxy.Address = new Uri("http://192.168.1.122:8888");
+            request.Proxy = proxy;
+            WebHeaderCollection headers = request.Headers;
+            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
+            Stream myResponseStream = response.GetResponseStream();
+            return myResponseStream;
+        }
+
         //POST缃戠粶璇锋眰
         public static string HttpPost(String url, Dictionary<String, String> paramsMap,Dictionary<String, String> headerMap) {
             string retString = string.Empty;
 
             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
+            request.CookieContainer = cookieContainer;
             request.Method = "POST";
             request.Timeout = 60000;
             request.ContentType = "application/x-www-form-urlencoded";
@@ -63,7 +84,7 @@
                 StringBuilder buffer = new StringBuilder();
                 foreach (KeyValuePair<string, string> kvp in paramsMap)
                 {
-                    buffer.AppendFormat("&{0}={1}", kvp.Key, kvp.Value);
+                    buffer.AppendFormat("&{0}={1}", kvp.Key, UrlEncode(kvp.Value));
                 }
 
                 if (buffer.ToString().StartsWith("&"))
@@ -82,5 +103,17 @@
             myResponseStream.Close();
             return retString;
         }
+
+
+        public static string UrlEncode(string str){
+                StringBuilder sb = new StringBuilder();
+                byte[] byStr = System.Text.Encoding.UTF8.GetBytes(str);
+                for (int i = 0; i < byStr.Length; i++)
+                {
+                    sb.Append(@"%" + Convert.ToString(byStr[i], 16));
+                }
+                return (sb.ToString());
+        }
+    
     }
 }

--
Gitblit v1.8.0