/// <summary>
/// Post请求
/// </summary>
/// <param name="url">URL路径</param>
/// <param name="postData">请求体</param>
/// <param name="head">头信息</param>
/// <returns></returns>
public static string Post(string url, string postData, Dictionary<string, string> head,string contentType = "application/json")
{
string result = string.Empty;
using (var client = new HttpClient())
{
StringContent content = new StringContent(postData);
content.Headers.ContentType = new MediaTypeHeaderValue(contentType);
foreach(var v in head)
{
content.Headers.Add(v.Key, v.Value);
}
var response = client.PostAsync(url, content).Result;
if (response.IsSuccessStatusCode)
{
result = response.Content.ReadAsStringAsync().Result;
}
}
return result;
}
网友评论