2023-12-30 04:27:31 -05:00
|
|
|
|
|
|
|
|
|
|
|
using System.Net;
|
|
|
|
using System.Net.Http.Json;
|
|
|
|
|
2024-01-05 05:07:41 -05:00
|
|
|
public class WebHelper {
|
2023-12-30 04:27:31 -05:00
|
|
|
private static HttpClient _client = new HttpClient();
|
|
|
|
|
2024-01-05 05:07:41 -05:00
|
|
|
public void AddHeader(string key, string? value) {
|
2023-12-30 04:27:31 -05:00
|
|
|
_client.DefaultRequestHeaders.Add(key, value);
|
|
|
|
}
|
|
|
|
|
2024-01-05 05:07:41 -05:00
|
|
|
public async Task<T?> GetJson<T>(string uri) {
|
2023-12-30 04:27:31 -05:00
|
|
|
return (T) await _client.GetFromJsonAsync(uri, typeof(T));
|
|
|
|
}
|
|
|
|
|
2024-01-05 05:07:41 -05:00
|
|
|
public async Task<HttpResponseMessage> Get(string uri) {
|
2023-12-30 04:27:31 -05:00
|
|
|
return await _client.GetAsync(uri);
|
|
|
|
}
|
|
|
|
|
2024-01-05 05:07:41 -05:00
|
|
|
public async Task<HttpResponseMessage> Post<T>(string uri, T data) {
|
2023-12-30 04:27:31 -05:00
|
|
|
return await _client.PostAsJsonAsync(uri, data);
|
|
|
|
}
|
|
|
|
|
2024-01-05 05:07:41 -05:00
|
|
|
public async Task<HttpResponseMessage> Post(string uri) {
|
2023-12-30 04:27:31 -05:00
|
|
|
return await _client.PostAsJsonAsync(uri, new object());
|
|
|
|
}
|
|
|
|
}
|