using System.Net; using System.Net.Http; using Cysharp.Threading.Tasks; using System.Text; using System.Threading; using Newtonsoft.Json; namespace BITKit.HttpNet { [System.Serializable] public sealed class HttpClient : WebProvider { System.Net.Http.HttpClient client = new(); public override async UniTask GetAsync(string url, CancellationToken cancellationToken = default) { using var response = await client.GetAsync(url, cancellationToken); return await response.Content.ReadAsStringAsync(); } public override async UniTask PostAsync(string url, T value, CancellationToken cancellationToken = default) { HttpContent content = value switch { string _string => new StringContent(_string,Encoding.Unicode,"application/json"), _ => new StringContent(JsonConvert.SerializeObject(value),Encoding.Unicode,"application/json") }; using var response = await client.PostAsync(url, content, cancellationToken); if (response.StatusCode is HttpStatusCode.OK) { return await response.Content.ReadAsStringAsync(); } BIT4Log.Log(response.StatusCode); return response.StatusCode.ToString(); } } }