You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
870 B

5 months ago
using System.Text;
using log4net;
5 months ago
using Newtonsoft.Json;
namespace Common.Util;
public static class HttpUtil
{
private static readonly HttpClient httpClient = new HttpClient();
private static readonly ILog Log = LogManager.GetLogger(typeof(HttpUtil));
5 months ago
public static async void SendPostRequest<T>(T data, string url)
{
try
{
string jsonStr = JsonConvert.SerializeObject(data);
var content = new StringContent(jsonStr, Encoding.UTF8, "application/json");
5 months ago
HttpResponseMessage response = await httpClient.PostAsync(url, content);
5 months ago
if (response.IsSuccessStatusCode)
{
await response.Content.ReadAsStringAsync();
}
}
catch (Exception e)
5 months ago
{
Log.Info("HttpUtil SendPostRequest Error:"+e.StackTrace);
5 months ago
}
}
}