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 | 36 +++++++++++++++++++++++++-----------
1 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/HttpHelper.cs b/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/HttpHelper.cs
index 275eeae..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,23 +60,31 @@
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 = "", string contentType = "application/json", Dictionary<string, string>? headers = null)
@@ -121,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;
@@ -139,7 +149,7 @@
};
response = (HttpWebResponse)request.GetResponse();
- Stream webStream = response.GetResponseStream();
+ Stream webStream = response.GetResponseStream();
if (webStream == null)
{
throw new Exception("Network error");
@@ -148,6 +158,7 @@
int statsCode = (int)response.StatusCode;
resultReader = new StreamReader(webStream, Encoding.UTF8);
responseContent = resultReader.ReadToEnd();
+
if (response != null)
response.Close();
@@ -158,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