2020-03-11 17:35:30 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Net.Http;
|
2020-02-15 18:22:51 +08:00
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2020-03-05 12:17:50 +08:00
|
|
|
|
namespace AntBlazor
|
2020-02-15 18:22:51 +08:00
|
|
|
|
{
|
|
|
|
|
public static class HttpClientExtensions
|
|
|
|
|
{
|
|
|
|
|
public static async ValueTask<T> GetJsonAsync<T>(this HttpClient httpClient, string url)
|
|
|
|
|
{
|
|
|
|
|
var s = await httpClient.GetStreamAsync(url);
|
2020-03-11 17:35:30 +08:00
|
|
|
|
return await JsonSerializer.DeserializeAsync<T>(s, options: new JsonSerializerOptions()
|
|
|
|
|
{
|
|
|
|
|
PropertyNameCaseInsensitive = true,
|
|
|
|
|
ReadCommentHandling = JsonCommentHandling.Skip
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async ValueTask<T> GetJsonAsync<T>(this HttpClient httpClient, Uri url)
|
|
|
|
|
{
|
|
|
|
|
var s = await httpClient.GetStreamAsync(url);
|
|
|
|
|
return await JsonSerializer.DeserializeAsync<T>(s, options: new JsonSerializerOptions()
|
|
|
|
|
{
|
|
|
|
|
PropertyNameCaseInsensitive = true,
|
|
|
|
|
ReadCommentHandling = JsonCommentHandling.Skip
|
|
|
|
|
});
|
2020-02-15 18:22:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-05 12:17:50 +08:00
|
|
|
|
}
|