mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-15 09:21:24 +08:00
47ad157c8b
* refactor: make httpclient extensions internal * fix: set property name case-Insensitive
32 lines
976 B
C#
32 lines
976 B
C#
using System;
|
|
using System.Net.Http;
|
|
using System.Text.Json;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AntDesign.core.Extensions
|
|
{
|
|
internal static class HttpClientExtensions
|
|
{
|
|
public static async Task<TValue> GetFromJsonAsync<TValue>(this HttpClient client, string requestUri, CancellationToken cancellationToken = default)
|
|
{
|
|
if (client == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(client));
|
|
}
|
|
|
|
var res = await client.GetAsync(requestUri, cancellationToken);
|
|
if (res.IsSuccessStatusCode)
|
|
{
|
|
var json = await res.Content.ReadAsStreamAsync();
|
|
return await JsonSerializer.DeserializeAsync<TValue>(json, new JsonSerializerOptions()
|
|
{
|
|
PropertyNameCaseInsensitive = true,
|
|
}, cancellationToken);
|
|
}
|
|
|
|
return default;
|
|
}
|
|
}
|
|
}
|