From 4f39dcc195f28fa275fc2d065fbf1bf6a46c21b7 Mon Sep 17 00:00:00 2001 From: dengjunjie <dengjunjie@hnkhzn.com> Date: 星期二, 17 六月 2025 00:41:18 +0800 Subject: [PATCH] 优化出入库逻辑 --- 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Common/Http/HttpHelpers.cs | 34 +++++++++++++++++++++++++++++++++- 1 files changed, 33 insertions(+), 1 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Common/Http/HttpHelpers.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Common/Http/HttpHelpers.cs" index caabe50..f931036 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Common/Http/HttpHelpers.cs" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Common/Http/HttpHelpers.cs" @@ -1,6 +1,7 @@ 锘� using Newtonsoft.Json; using System.Net; +using System.Net.Http.Headers; using System.Text; using WIDESEA_Common.Log; @@ -8,7 +9,7 @@ { public class HttpHelpers { - private const int Timeout = 10 * 1000; + private const int Timeout = 20 * 1000; /// <summary> /// post璇锋眰 @@ -66,7 +67,38 @@ throw ex; } } + public static async Task<string?> PostAsync(string serviceAddress, string requestJson = null, string contentType = "application/json", Dictionary<string, string>? headers = null) + { + string result = string.Empty; + DateTime beginDate = DateTime.Now; + try + { + 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); + if (headers != null) + { + foreach (KeyValuePair<string, string> header in headers) + { + httpClient.DefaultRequestHeaders.Add(header.Key, header.Value); + } + } + result = await httpClient.PostAsync(serviceAddress, httpContent).Result.Content.ReadAsStringAsync(); + } + + return result; + } + catch (Exception ex) + { + throw new Exception(ex.Message); + } + finally + { + } + } /// <summary> /// post璇锋眰 /// </summary> -- Gitblit v1.9.3