|
|
|
@ -116,6 +116,45 @@ public class RequestHelper
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// http post请求
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="url">地址</param>
|
|
|
|
|
/// <param name="parameter">入参</param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <param name="headers">头信息</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
/// , string token ="", Dictionary<string, string> headers = null
|
|
|
|
|
public static async Task<string> PostJosnAsyncNoHeaders(string url, string parameter)
|
|
|
|
|
{
|
|
|
|
|
using (var client = new HttpClient())
|
|
|
|
|
{
|
|
|
|
|
//var data = new StringContent("param1=value1¶m2=value2", Encoding.UTF8, "application/x-www-form-urlencoded");
|
|
|
|
|
var data = new StringContent(parameter, Encoding.UTF8, "application/json");
|
|
|
|
|
//_logger.LogWarning($"data:{data.ToJsonString()};parameter:{parameter}");
|
|
|
|
|
// 添加header参数
|
|
|
|
|
//client.DefaultRequestHeaders.Add("Authorization", "Bearer your_token_here");
|
|
|
|
|
//foreach (var header in headers)
|
|
|
|
|
//{
|
|
|
|
|
// client.DefaultRequestHeaders.Add(header.Key, header.Value);
|
|
|
|
|
//}
|
|
|
|
|
//_logger.LogWarning($"header:{client.DefaultRequestHeaders.ToJsonString()}");
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var response = await client.PostAsync(url, data);
|
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
|
|
|
|
|
|
var responseBody = await response.Content.ReadAsStringAsync();
|
|
|
|
|
return responseBody;
|
|
|
|
|
}
|
|
|
|
|
catch (HttpRequestException e)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(e.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// http异步请求
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="url">url</param>
|
|
|
|
|