From 17e5dbd7bd0364e27a33f1a7dab91cf33d5dcabc Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期三, 04 三月 2026 11:52:12 +0800
Subject: [PATCH] 增强Redis缓存服务与设备通信优化

---
 Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Core/Helper/HttpHelper.cs |   24 +++++++++++++++---------
 1 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Core/Helper/HttpHelper.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Core/Helper/HttpHelper.cs
index 03706c4..122c2ed 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Core/Helper/HttpHelper.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Core/Helper/HttpHelper.cs
@@ -6,6 +6,7 @@
 using System.Security.Policy;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEAWCS_Core.Const;
 using WIDESEAWCS_Core.LogHelper;
 
 namespace WIDESEAWCS_Core.Helper
@@ -24,7 +25,7 @@
         /// 鏂规硶浼氳嚜鍔ㄨ褰曡姹傛棩蹇楋紝鍖呭惈璇锋眰鍦板潃銆佸搷搴斿唴瀹瑰拰鑰楁椂绛変俊鎭�
         /// 榛樿璇锋眰瓒呮椂鏃堕棿涓�60绉�
         /// </remarks>
-        public static async Task<string> GetAsync(string serviceAddress, string contentType = "application/json", int timeOut = 60, Dictionary<string, string>? headers = null)
+        public static async Task<string> GetAsync(string serviceAddress, string contentType = "application/json", int timeOut = CommunicationConst.HttpDefaultTimeoutSeconds, Dictionary<string, string>? headers = null)
         {
             string result = string.Empty;
             DateTime beginDate = DateTime.Now;
@@ -39,7 +40,8 @@
                         httpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
                 }
 
-                result = await httpClient.GetAsync(serviceAddress).Result.Content.ReadAsStringAsync();
+                HttpResponseMessage response = await httpClient.GetAsync(serviceAddress);
+                result = await response.Content.ReadAsStringAsync();
                 return result;
             }
             catch (Exception e)
@@ -63,7 +65,7 @@
         /// <remarks>
         /// 鑷姩璁板綍璇锋眰鏃ュ織锛屽寘鍚姹傚湴鍧�銆佽姹傛暟鎹�佸搷搴旀暟鎹拰鑰楁椂
         /// </remarks>
-        public static async Task<string?> PostAsync(string serviceAddress, string requestJson = null, string contentType = "application/json", int timeOut = 60, Dictionary<string, string>? headers = null)
+        public static async Task<string?> PostAsync(string serviceAddress, string requestJson = null, string contentType = "application/json", int timeOut = CommunicationConst.HttpDefaultTimeoutSeconds, Dictionary<string, string>? headers = null)
         {
             string result = string.Empty;
             DateTime beginDate = DateTime.Now;
@@ -86,7 +88,8 @@
                             httpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
                     }
 
-                    result = await httpClient.PostAsync(serviceAddress, httpContent).Result.Content.ReadAsStringAsync();
+                    HttpResponseMessage response = await httpClient.PostAsync(serviceAddress, httpContent);
+                    result = await response.Content.ReadAsStringAsync();
                 }
                 return result;
             }
@@ -111,7 +114,7 @@
         /// /// <remarks>
         /// 璇ユ柟娉曚細鑷姩璁板綍璇锋眰鏃ュ織锛屽寘鍚姹傚湴鍧�銆佽姹傛暟鎹�佸搷搴旀暟鎹拰鑰楁椂
         /// </remarks>
-        public static string Get(string serviceAddress, string contentType = "application/json", int timeOut = 60, Dictionary<string, string>? headers = null)
+        public static string Get(string serviceAddress, string contentType = "application/json", int timeOut = CommunicationConst.HttpDefaultTimeoutSeconds, Dictionary<string, string>? headers = null)
         {
             string result = string.Empty;
             DateTime beginDate = DateTime.Now;
@@ -126,7 +129,8 @@
                         httpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
                 }
 
-                result = httpClient.GetStringAsync(serviceAddress).Result;
+                Task<string> task = httpClient.GetStringAsync(serviceAddress);
+                result = task.GetAwaiter().GetResult();
                 return result;
             }
             catch (Exception e)
@@ -151,7 +155,7 @@
         /// <remarks>
         /// 璇ユ柟娉曚細鑷姩璁板綍璇锋眰鏃ュ織锛屽寘鍚姹傚湴鍧�銆佽姹傛暟鎹�佸搷搴旀暟鎹拰鑰楁椂
         /// </remarks>
-        public static string Post(string serviceAddress, string requestJson = null, string contentType = "application/json", int timeOut = 60, Dictionary<string, string>? headers = null)
+        public static string Post(string serviceAddress, string requestJson = null, string contentType = "application/json", int timeOut = CommunicationConst.HttpDefaultTimeoutSeconds, Dictionary<string, string>? headers = null)
         {
             string result = string.Empty;
             DateTime beginDate = DateTime.Now;
@@ -174,10 +178,12 @@
                             httpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
                     }
 
-                    HttpResponseMessage message = httpClient.PostAsync(serviceAddress, httpContent).Result;
+                    Task<HttpResponseMessage> postTask = httpClient.PostAsync(serviceAddress, httpContent);
+                    HttpResponseMessage message = postTask.GetAwaiter().GetResult();
                     if (message.StatusCode == HttpStatusCode.OK)
                     {
-                        result = message.Content.ReadAsStringAsync().Result;
+                        Task<string> readTask = message.Content.ReadAsStringAsync();
+                        result = readTask.GetAwaiter().GetResult();
                     }
                     else
                     {

--
Gitblit v1.9.3