using System; using System.Collections.Generic; using System.Linq; using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; namespace DS.WMS.Core.QuarztJobs.Other { public class HttpHellp { private static readonly HttpClient _httpClient = new HttpClient { Timeout = TimeSpan.FromSeconds(60) }; /// /// post请求 /// /// 请求地址 /// 请求参数 /// 请求头 /// public static async Task PostAsync(string serviceAddress, string requestJson = null, Dictionary headers = null) { try { string result = string.Empty; Uri postUrl = new Uri(serviceAddress); using (HttpContent httpContent = new StringContent(requestJson)) { httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); if (headers != null) { foreach (var header in headers) { httpContent.Headers.Add(header.Key, header.Value); } } var response = await _httpClient.PostAsync(serviceAddress, httpContent); result = await response.Content.ReadAsStringAsync(); } return result; } catch (Exception e) { Console.WriteLine(e.Message); } return null; } } }