分离玩家信息插件,以及更新检测
This commit is contained in:
27
Utils/Network.cs
Normal file
27
Utils/Network.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Net.Http;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
|
||||
namespace AnotherReplayReader.Utils
|
||||
{
|
||||
public static class Network
|
||||
{
|
||||
public static readonly JsonSerializerOptions CommonJsonOptions = new()
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
||||
};
|
||||
|
||||
public static string UrlEncode(string text) => HttpUtility.UrlEncode(text);
|
||||
|
||||
public static async Task<T?> HttpGetJson<T>(string url,
|
||||
CancellationToken cancelToken = default)
|
||||
{
|
||||
using var client = new HttpClient();
|
||||
using var response = await client.GetAsync(url, cancelToken).ConfigureAwait(false);
|
||||
using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||
return await JsonSerializer.DeserializeAsync<T>(stream, CommonJsonOptions, cancelToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user