| | |
| | | using Microsoft.Extensions.Configuration; |
| | | using Microsoft.Extensions.Logging; |
| | | using Newtonsoft.Json; |
| | | using WIDESEAWCS_Core.Caches; |
| | | |
| | | namespace WIDESEA_Core |
| | | { |
| | | public class HttpClientHelper |
| | | { |
| | | private readonly IHttpClientFactory _httpClientFactory; |
| | | private readonly ICacheService _cache; |
| | | |
| | | public HttpClientHelper(IHttpClientFactory httpClientFactory, IConfiguration configuration = null) |
| | | public HttpClientHelper(IHttpClientFactory httpClientFactory, ICacheService cache, IConfiguration configuration = null) |
| | | { |
| | | _httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory)); |
| | | _cache = cache ?? throw new ArgumentNullException(nameof(cache)); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <returns></returns> |
| | | public HttpResponseResult Post(string url, string content, string contentType = "application/json", HttpRequestConfig? config = null) |
| | | { |
| | | url = _cache.Get(url); |
| | | HttpResponseResult httpResponseResult = ExecuteAsync(async (client) => |
| | | { |
| | | var request = new HttpRequestMessage(HttpMethod.Post, url); |