1
This commit is contained in:
38
Packages/Core/Net/HttpClient.cs
Normal file
38
Packages/Core/Net/HttpClient.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user