1
This commit is contained in:
19
Assets/BITKit/Core/Extensions/HttpClient.cs
Normal file
19
Assets/BITKit/Core/Extensions/HttpClient.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user