From deb1079692d620377c5cdee9ed02b59223a2206f Mon Sep 17 00:00:00 2001
From: 陈勇 <chenyong@hnkhzn.com>
Date: 星期二, 19 十一月 2024 10:21:05 +0800
Subject: [PATCH] 合并
---
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_Common/HttpClient/HttpsClient.cs | 26 ++++++++++++++++++++------
1 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_Common/HttpClient/HttpsClient.cs b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_Common/HttpClient/HttpsClient.cs
index b06c608..571ea6a 100644
--- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_Common/HttpClient/HttpsClient.cs
+++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_Common/HttpClient/HttpsClient.cs
@@ -13,7 +13,7 @@
private static readonly LogFactory LogFactory = new LogFactory();
// 灏佽涓�涓敤HttpClient鍙戦�丟ET璇锋眰鐨勬柟娉曟湁鍙傛暟
- public static async Task<string> GetAsync(string url, Dictionary<string, string> parameters)
+ public static async Task<string> GetAsync(string url, Dictionary<string, object> parameters)
{
// 璁板綍璇锋眰鍙傛暟
LogRequestParameters(parameters);
@@ -43,7 +43,7 @@
}
// 灏佽涓�涓敤HttpClient鍙戦�丳ost璇锋眰鐨勬柟娉曟湁鍙傛暟
- public static async Task<string> PostAsync(string url, Dictionary<string, string> parameters)
+ public static async Task<string> PostAsync(string url, Dictionary<string, object> parameters)
{
// 璁板綍璇锋眰鍙傛暟
LogRequestParameters(parameters);
@@ -52,10 +52,15 @@
using (HttpClient client = new HttpClient())
{
// 灏嗗弬鏁拌浆鎹负FormUrlEncodedContent
- FormUrlEncodedContent content = new FormUrlEncodedContent(parameters);
+ string content = JsonConvert.SerializeObject(parameters);
- // 鍙戦�丳OST璇锋眰骞惰幏鍙栧搷搴�
- HttpResponseMessage response = await client.PostAsync(url, content);
+ var request = new HttpRequestMessage(HttpMethod.Post, url);
+
+ request.Content = new StringContent(content, Encoding.UTF8, "application/json");
+ //var content = new FormUrlEncodedContent(ConvertToKeyValuePairs(parameters));
+ //// 鍙戦�丳OST璇锋眰骞惰幏鍙栧搷搴�
+ //HttpResponseMessage response = await client.PostAsync(url, content);
+ HttpResponseMessage response = await client.SendAsync(request);
// 纭繚鍝嶅簲鎴愬姛
response.EnsureSuccessStatusCode();
@@ -71,7 +76,7 @@
}
}
- private static void LogRequestParameters(Dictionary<string, string> parameters)
+ private static void LogRequestParameters(Dictionary<string, object> parameters)
{
LogFactory.GetLog("API鎺ュ彛").Info(true, "璇锋眰鍙傛暟: " + JsonConvert.SerializeObject(parameters));
}
@@ -80,4 +85,13 @@
{
LogFactory.GetLog("API鎺ュ彛").Info(true, "鍝嶅簲鍙傛暟: " + responseBody);
}
+
+ private static IEnumerable<KeyValuePair<string, string>> ConvertToKeyValuePairs(Dictionary<string, object> parameters)
+ {
+ foreach (var kvp in parameters)
+ {
+ yield return new KeyValuePair<string, string>(kvp.Key, kvp.Value?.ToString());
+ }
+ }
+
}
\ No newline at end of file
--
Gitblit v1.9.3