| | |
| | | |
| | | 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" }, |
| | |
| | | { "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(); |
| | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |