From bd327b1c240ed2aca48ab6e427285dcb12235f72 Mon Sep 17 00:00:00 2001
From: pengmn <pmn@HanInfo>
Date: 星期三, 02 七月 2025 17:38:11 +0800
Subject: [PATCH] 1

---
 HH.WCS.Mobox3.HangYang/util/HttpHelper.cs |  118 +++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 95 insertions(+), 23 deletions(-)

diff --git a/HH.WCS.Mobox3.HangYang/util/HttpHelper.cs b/HH.WCS.Mobox3.HangYang/util/HttpHelper.cs
index 56bbfa2..4b68dc5 100644
--- a/HH.WCS.Mobox3.HangYang/util/HttpHelper.cs
+++ b/HH.WCS.Mobox3.HangYang/util/HttpHelper.cs
@@ -6,18 +6,31 @@
 using System.Text;
 
 namespace HH.WCS.HangYang.util {
-    public class HttpHelper {
-        public string WebPost(string url, string postData, string cotentType = "application/json") {
+    public class HttpHelper 
+    {
+        #region  鏉哀WebHelper
+
+        public string WebPost(string url, string postData, string cotentType = "application/json", string AppKey = "", string ReqTime = "", string ReqVerify = "")
+        {
             Console.WriteLine(url);
             WebRequest request = WebRequest.Create(url);
             request.Method = "POST";
+
+
+            if (!string.IsNullOrEmpty(AppKey) && !string.IsNullOrEmpty(ReqTime) && !string.IsNullOrEmpty(ReqVerify))
+            {
+                request.Headers.Set("AppKey", AppKey);
+                request.Headers.Set("ReqTime", ReqTime);
+                request.Headers.Set("ReqVerify", ReqVerify);
+            }
             //string postData = JsonConvert.SerializeObject(data); ;
             byte[] byteArray = Encoding.UTF8.GetBytes(postData);
             request.ContentType = cotentType;
             request.ContentLength = byteArray.Length;
             request.Timeout = 3000;
 
-            try {
+            try
+            {
                 Stream dataStream = request.GetRequestStream();
                 dataStream.Write(byteArray, 0, byteArray.Length);
                 dataStream.Close();
@@ -31,13 +44,52 @@
                 response.Close();
                 return responseFromServer;
             }
-            catch (Exception e) {
+            catch (Exception e)
+            {
                 Console.WriteLine(e.Message);
                 return "";
             }
         }
 
-        public string WebGet(string url) {
+
+        #endregion
+
+        #region WebHelper
+        public string WebHttpPost(string url, string postData, string cotentType = "application/json")
+        {
+            Console.WriteLine(url);
+            WebRequest request = WebRequest.Create(url);
+            request.Method = "POST";
+            //string postData = JsonConvert.SerializeObject(data); ;
+            byte[] byteArray = Encoding.UTF8.GetBytes(postData);
+            request.ContentType = cotentType;
+            request.ContentLength = byteArray.Length;
+            request.Timeout = 3000;
+
+            try
+            {
+                Stream dataStream = request.GetRequestStream();
+                dataStream.Write(byteArray, 0, byteArray.Length);
+                dataStream.Close();
+                WebResponse response = request.GetResponse();
+                //Console.WriteLine(((HttpWebResponse)response).StatusDescription);
+                dataStream = response.GetResponseStream();
+                StreamReader reader = new StreamReader(dataStream, Encoding.UTF8);
+                string responseFromServer = reader.ReadToEnd();
+                reader.Close();
+                dataStream.Close();
+                response.Close();
+                return responseFromServer;
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine(e.Message);
+                return "";
+            }
+        }
+
+        public string WebGet(string url)
+        {
             //using (var client = new HttpClient()) {
             //	//璇锋眰缁撴灉
             //	string result = client.GetAsync(url).Result.Content.ReadAsStringAsync().Result;
@@ -51,7 +103,8 @@
             request.Timeout = 6000;
             request.Method = "GET";
 
-            try {
+            try
+            {
                 WebResponse response = request.GetResponse();
                 Stream dataStream = response.GetResponseStream();
                 StreamReader reader = new StreamReader(dataStream);
@@ -63,29 +116,34 @@
                 Console.WriteLine(responseFromServer);
                 return responseFromServer;
             }
-            catch (Exception e) {
+            catch (Exception e)
+            {
                 return "";
             }
         }
 
-        public string Get(string url, string contentType = "application/x-www-form-urlencoded") {
+        public string Get(string url, string contentType = "application/x-www-form-urlencoded")
+        {
             WebRequest request = WebRequest.Create(url);
             request.Method = "Get";
             request.ContentType = contentType;
             StreamReader reader = null;
             Stream stream = null;
             WebResponse rsp = null;
-            try {
+            try
+            {
 
                 rsp = request.GetResponse();
                 stream = rsp.GetResponseStream();
                 reader = new StreamReader(stream);
                 return reader.ReadToEnd();
             }
-            catch {
+            catch
+            {
                 return "";
             }
-            finally {
+            finally
+            {
                 // 閲婃斁璧勬簮
                 if (reader != null) reader.Close();
                 if (stream != null) stream.Close();
@@ -94,7 +152,8 @@
 
         }
 
-        public string Post(string url, string postData, string contentType = "application/json", string sessionId = "") {
+        public string Post(string url, string postData, string contentType = "application/json", string sessionId = "")
+        {
             Console.WriteLine(url);
             WebRequest request = WebRequest.Create(url);
             request.Method = "POST";
@@ -102,13 +161,15 @@
             request.ContentType = contentType;
             request.ContentLength = byteArray.Length;
             request.Timeout = 3000;
-            if (sessionId != "") {
+            if (sessionId != "")
+            {
                 request.Headers.Set("ASP.NET_SessionId", sessionId);
             }
             StreamReader reader = null;
             Stream stream = null;
             WebResponse rsp = null;
-            try {
+            try
+            {
                 stream = request.GetRequestStream();
                 stream.Write(byteArray, 0, byteArray.Length);
                 stream.Close();
@@ -117,11 +178,13 @@
                 reader = new StreamReader(stream);
                 return reader.ReadToEnd();
             }
-            catch (Exception ex) {
+            catch (Exception ex)
+            {
                 Console.WriteLine($"{url} err={ex.Message}");
                 return "";
             }
-            finally {
+            finally
+            {
                 // 閲婃斁璧勬簮
                 if (reader != null) reader.Close();
                 if (stream != null) stream.Close();
@@ -131,29 +194,34 @@
         }
 
 
-        public string Post(string url, Dictionary<string, string> dic) {
+        public string Post(string url, Dictionary<string, string> dic)
+        {
             var param = dic.Select(a => { return string.Format("{0}={1}", a.Key, a.Value); }).ToList();
             return Post(url, string.Join("&", param), "application/x-www-form-urlencoded");
 
         }
 
-        public string PostWithCookie(string url, string sessinId) {
+        public string PostWithCookie(string url, string sessinId)
+        {
             return PostWithCookie(url, "", "", sessinId);
         }
-        public string PostWithCookie(string url, string postData, string contentType = "application/json", string sessionId = "") {
+        public string PostWithCookie(string url, string postData, string contentType = "application/json", string sessionId = "")
+        {
             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
             request.Method = "POST";
             byte[] byteArray = Encoding.UTF8.GetBytes(postData);
             request.ContentType = contentType;
             request.ContentLength = byteArray.Length;
-            if (sessionId != "") {
+            if (sessionId != "")
+            {
                 request.CookieContainer = new CookieContainer();
                 request.CookieContainer.SetCookies(new Uri("http://" + request.RequestUri.Authority), "ASP.NET_SessionId=" + sessionId);
             }
             StreamReader reader = null;
             Stream stream = null;
             WebResponse rsp = null;
-            try {
+            try
+            {
                 stream = request.GetRequestStream();
                 stream.Write(byteArray, 0, byteArray.Length);
                 stream.Close();
@@ -162,10 +230,12 @@
                 reader = new StreamReader(stream);
                 return reader.ReadToEnd();
             }
-            catch {
+            catch
+            {
                 return "";
             }
-            finally {
+            finally
+            {
                 // 閲婃斁璧勬簮
                 if (reader != null) reader.Close();
                 if (stream != null) stream.Close();
@@ -173,6 +243,8 @@
             }
 
         }
+        #endregion
+
 
 
     }

--
Gitblit v1.9.1