39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Cysharp.Threading.Tasks;
|
|
using System.Threading;
|
|
using System.Net.Http;
|
|
using Newtonsoft.Json.Serialization;
|
|
using Newtonsoft.Json;
|
|
namespace BITKit.HttpNet
|
|
{
|
|
[System.Serializable]
|
|
public sealed class HttpClient : WebProvider
|
|
{
|
|
System.Net.Http.HttpClient client = new();
|
|
public override async UniTask<string> GetAsync(string url, CancellationToken cancellationToken = default)
|
|
{
|
|
using (var response = await client.GetAsync(url))
|
|
{
|
|
return await response.Content.ReadAsStringAsync();
|
|
}
|
|
}
|
|
|
|
public override async UniTask<string> PostAsync<T>(string url, T value, CancellationToken cancellationToken = default)
|
|
{
|
|
HttpContent content = null;
|
|
switch (value)
|
|
{
|
|
case string _string:
|
|
content = new StringContent(_string);
|
|
break;
|
|
default:
|
|
//content = new ByteArrayContent(.WriteAsBytes(value));
|
|
break;
|
|
}
|
|
using var response = await client.PostAsync(url, content, cancellationToken);
|
|
return await response.Content.ReadAsStringAsync();
|
|
}
|
|
}
|
|
}
|