|
|
|
@ -1,5 +1,9 @@
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Http.Headers;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
|
using System.Security.Policy;
|
|
|
|
|
|
|
|
|
|
namespace DS.Module.Core.Helpers;
|
|
|
|
|
|
|
|
|
@ -7,7 +11,7 @@ namespace DS.Module.Core.Helpers;
|
|
|
|
|
/// 请求帮助类
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class RequestHelper
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
public static string Post(string postData, string Url,int timeout = 60000)
|
|
|
|
|
{
|
|
|
|
|
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Url);
|
|
|
|
@ -72,7 +76,45 @@ public class RequestHelper
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
/// <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> PostAsyncNoHeaders(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/x-www-form-urlencoded");
|
|
|
|
|
//_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>
|
|
|
|
|