public async Task <HttpClientServiceResult <string> > AddAsync(string url, ItemModel itemModel) { await TokenProvider.AttachAccessTokenToHeader(HttpClient, HttpContextAccessor); HttpResponseMessage response; try { var json = JsonSerializer.Serialize(itemModel); //Needed to setup the body of the request var data = new StringContent(json, Encoding.UTF8, "application/json"); response = await HttpClient.PostAsync(url, data); response.EnsureSuccessStatusCode(); } catch (HttpRequestException e) { return(new HttpClientServiceResult <string> { Content = null !, StatusCode = 500, // Server Error! Error = e.Message });
public async Task <ServiceResult <string> > SearchProductsAsync(string url) { await TokenProvider.AttachAccessTokenToHeader(_storeHttpClient, _httpContextAccessor); HttpResponseMessage response; try { response = await _storeHttpClient.GetAsync(url); response.EnsureSuccessStatusCode(); } catch (HttpRequestException e) { return(new ServiceResult <string> { Content = null !, StatusCode = 500, // Server Error! Error = e.Message });