23 lines
660 B
C#
23 lines
660 B
C#
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using Cysharp.Threading.Tasks;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace BITKit
|
|
{
|
|
public static class HttpClientExtensions
|
|
{
|
|
public static async UniTask<string> PostJsonAsync(this HttpClient self, string requestUrl, object value , CancellationToken cancellationToken=default)
|
|
{
|
|
var json = JsonConvert.SerializeObject(value);
|
|
if (value is string j)
|
|
{
|
|
json = j;
|
|
}
|
|
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
|
var response =await self.PostAsync(requestUrl, content, cancellationToken);
|
|
return await response.Content.ReadAsStringAsync();
|
|
}
|
|
}
|
|
} |