This commit is contained in:
CortexCore
2023-06-05 16:25:06 +08:00
parent 9027120bb8
commit 4565ff2e35
2947 changed files with 0 additions and 0 deletions

38
Core/Net/HttpClient.cs Normal file
View File

@@ -0,0 +1,38 @@
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();
}
}
}