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.

40 lines
958 B

6 months ago
using System.Text;
using Newtonsoft.Json;
namespace Common.Util;
public static class HttpUtil
{
private static readonly HttpClient httpClient = new HttpClient();
public static async void SendPostRequest<T>(T data, string url)
{
string jsonStr = JsonConvert.SerializeObject(data);
var content = new StringContent(jsonStr, Encoding.UTF8, "application/json");
HttpResponseMessage response = await httpClient.PostAsync(url, content);
if (response.IsSuccessStatusCode)
{
await response.Content.ReadAsStringAsync();
}
}
4 months ago
public static async void SendGetRequest(string url)
{
try
{
HttpResponseMessage response = await httpClient.GetAsync(url);
if (response.IsSuccessStatusCode)
{
await response.Content.ReadAsStringAsync();
}
}
catch
{
}
}
6 months ago
}