111
啊鑫
2025-08-29 d1dc6aaa453c38c6282930d85c58388b89aac065
MES.Service/Dto/webApi/RealTimeInventory/HttpClientEx.cs
@@ -4,25 +4,25 @@
namespace MES.Service.Dto.webApi.RealTimeInventory;
public
public
    // HTTP客户端类,用于发送请求和获取响应
    class HttpClientEx
{
    private static readonly CookieContainer Cookie = new();
    public string Url { get; set; }
    public string Content { get; set; }
    static CookieContainer Cookie = new CookieContainer();
    public string AsyncRequest()
    {
        HttpWebRequest httpRequest = HttpWebRequest.Create(Url) as HttpWebRequest;
        var httpRequest = HttpWebRequest.Create(Url) as HttpWebRequest;
        httpRequest.Method = "POST";
        httpRequest.ContentType = "application/json";
        httpRequest.CookieContainer = Cookie;
        httpRequest.Timeout = 1000 * 60 * 10; // 10分钟超时
        using (Stream reqStream = httpRequest.GetRequestStream())
        using (var reqStream = httpRequest.GetRequestStream())
        {
            JObject jObj = new JObject
            var jObj = new JObject
            {
                { "format", 1 },
                { "useragent", "ApiClient" },
@@ -32,7 +32,7 @@
                { "v", "1.0" }
            };
            string sContent = jObj.ToString();
            var sContent = jObj.ToString();
            var bytes = UnicodeEncoding.UTF8.GetBytes(sContent);
            reqStream.Write(bytes, 0, bytes.Length);
            reqStream.Flush();
@@ -46,4 +46,4 @@
            }
        }
    }
}
}