更改文件架构
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace BITKit.HttpNet
|
||||
{
|
||||
[System.Serializable]
|
||||
@@ -13,26 +16,24 @@ namespace BITKit.HttpNet
|
||||
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();
|
||||
}
|
||||
using var response = await client.GetAsync(url, cancellationToken);
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
|
||||
public override async UniTask<string> PostAsync<T>(string url, T value, CancellationToken cancellationToken = default)
|
||||
{
|
||||
HttpContent content = null;
|
||||
switch (value)
|
||||
HttpContent content = value switch
|
||||
{
|
||||
case string _string:
|
||||
content = new StringContent(_string);
|
||||
break;
|
||||
default:
|
||||
//content = new ByteArrayContent(.WriteAsBytes(value));
|
||||
break;
|
||||
}
|
||||
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);
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
if (response.StatusCode is HttpStatusCode.OK)
|
||||
{
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
BIT4Log.Log<HttpClient>(response.StatusCode);
|
||||
return response.StatusCode.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user