19 lines
610 B
C#
19 lines
610 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);
|
||
|
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
||
|
var response =await self.PostAsync(requestUrl, content, cancellationToken);
|
||
|
return await response.Content.ReadAsStringAsync();
|
||
|
}
|
||
|
}
|
||
|
}
|