public async Task <APICallResult <TReturnValue> > GetAsJsonAsync <TParameter, TReturnValue>(string url, TParameter model) { APICallResult <TReturnValue> result = new APICallResult <TReturnValue>(); string urlwithquerystring = url + "?" + HttpHelper.ToQueryString <TParameter>(model); try { HttpResponseMessage response = await httpClient.GetAsync(new Uri(urlwithquerystring)); if (response.IsSuccessStatusCode) { result.Succeeded = true; result.Value = await response.Content.ReadAsAsync <TReturnValue>(); } else { result.Succeeded = true; result.ErrorMessage = response.ReasonPhrase; } } catch (Exception ex) { result.Succeeded = true; result.ErrorMessage = ex.Message; } return(result); }
public async Task <APICallResult <string> > GetAsStringAsync(string url) { APICallResult <string> result = new APICallResult <string>(); try { HttpResponseMessage response = await httpClient.GetAsync(new Uri(url)); if (response.IsSuccessStatusCode) { result.Succeeded = true; result.Value = await response.Content.ReadAsStringAsync(); } else { result.Succeeded = true; result.ErrorMessage = response.ReasonPhrase; } } catch (Exception ex) { result.Succeeded = true; result.ErrorMessage = ex.Message; } return(result); }
public async Task <APICallResult <TReturnValue> > PutAsJsonAsync <TParameter, TReturnValue>(string url, TParameter model) { APICallResult <TReturnValue> result = new APICallResult <TReturnValue>(); try { HttpResponseMessage response = await httpClient.PutAsJsonAsync(url, model); if (response.IsSuccessStatusCode) { result.Succeeded = true; result.Value = await response.Content.ReadAsAsync <TReturnValue>(); } else { result.Succeeded = true; result.ErrorMessage = response.ReasonPhrase; } } catch (Exception ex) { result.Succeeded = true; result.ErrorMessage = ex.Message; } return(result); }