From d01658c63cd541fe4ea5cec5c4bd7f23b9408cdb Mon Sep 17 00:00:00 2001
From: 647556386 <647556386@qq.com>
Date: 星期六, 18 十月 2025 15:04:56 +0800
Subject: [PATCH] 前端,pda,后端接口更改,新增,优化

---
 WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/HttpHelper.cs |   60 ++++++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 42 insertions(+), 18 deletions(-)

diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/HttpHelper.cs b/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/HttpHelper.cs
index adbae83..8853a91 100644
--- a/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/HttpHelper.cs
+++ b/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/HttpHelper.cs
@@ -6,6 +6,7 @@
 using System.Net.Http.Headers;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEA_Core.LogHelper;
 
 namespace WIDESEA_Core.Helper
 {
@@ -59,38 +60,53 @@
 
         public static string Get(string serviceAddress, string contentType = "application/json", Dictionary<string, string>? headers = null)
         {
+            string text = string.Empty;
+            DateTime now = DateTime.Now;
             try
             {
-                string result = string.Empty;
                 using HttpClient httpClient = new HttpClient();
                 httpClient.Timeout = new TimeSpan(0, 0, 60);
+                if (headers != null)
+                {
+                    foreach (KeyValuePair<string, string> header in headers)
+                    {
+                        httpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
+                    }
+                }
 
-                foreach (var header in headers)
-                    httpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
-
-                result = httpClient.GetStringAsync(serviceAddress).Result;
-                return result;
+                text = httpClient.GetStringAsync(serviceAddress).Result;
+                return text;
             }
-            catch (Exception e)
+            catch (Exception ex)
             {
-                Console.WriteLine(e.Message);
+                throw new Exception(ex.Message);
             }
-            return null;
+            finally
+            {
+                Logger.Add(serviceAddress, "", text, now);
+            }
         }
 
-        public static string Post(string serviceAddress, string requestJson = null, string contentType = "application/json", Dictionary<string, string>? headers = null)
+        public static string Post(string serviceAddress, string requestJson = "", string contentType = "application/json", Dictionary<string, string>? headers = null)
         {
+            string result = string.Empty;
+            DateTime beginDate = DateTime.Now;
             try
             {
-                string result = string.Empty;
                 using (HttpContent httpContent = new StringContent(requestJson))
                 {
                     httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                     using HttpClient httpClient = new HttpClient();
                     httpClient.Timeout = new TimeSpan(0, 0, 60);
-
-                    foreach (var header in headers)
-                        httpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
+                    if (serviceAddress.Contains("cimforce/AtomJsonService"))
+                    {
+                        httpClient.Timeout = new TimeSpan(0, 0, 30);
+                    }
+                    if (headers != null)
+                    {
+                        foreach (var header in headers)
+                            httpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
+                    }
 
                     result = httpClient.PostAsync(serviceAddress, httpContent).Result.Content.ReadAsStringAsync().Result;
                 }
@@ -98,9 +114,12 @@
             }
             catch (Exception e)
             {
-                Console.WriteLine(e.Message);
+                throw new Exception(e.Message);
             }
-            return null;
+            finally
+            {
+                //Logger.Add(serviceAddress, requestJson, result, beginDate);
+            }
         }
         /// <summary>
         /// post璇锋眰
@@ -111,6 +130,7 @@
         /// <returns></returns>
         public static T Post<T>(string url, object parm, string rquestName = "") where T : class
         {
+            DateTime beginDate = DateTime.Now;
             HttpWebResponse response = null;
             StreamReader resultReader = null;
             string responseContent = string.Empty;
@@ -129,7 +149,7 @@
                 };
 
                 response = (HttpWebResponse)request.GetResponse();
-                Stream webStream = response.GetResponseStream();
+               Stream webStream = response.GetResponseStream();
                 if (webStream == null)
                 {
                     throw new Exception("Network error");
@@ -138,6 +158,7 @@
                 int statsCode = (int)response.StatusCode;
                 resultReader = new StreamReader(webStream, Encoding.UTF8);
                 responseContent = resultReader.ReadToEnd();
+
 
                 if (response != null)
                     response.Close();
@@ -148,13 +169,16 @@
                 {
                     throw new Exception("寮傚父锛屽搷搴旂爜锛�" + statsCode.ToString());
                 }
-
                 return JsonConvert.DeserializeObject<T>(responseContent);
             }
             catch (Exception ex)
             {
                 throw ex;
             }
+            finally
+            {
+                Logger.Add(url, parm, responseContent, beginDate);
+            }
         }
 
     }

--
Gitblit v1.9.3