public async Task <IResponseResult> ExecuteRequestAsync(HttpMethod method, string url, RequestBody body, IHeaderCollection headers) { var payload = RestHelper.GenerateBody(body, method); this.Client.DefaultRequestHeaders.Clear(); if (headers != null) { foreach (var header in headers) { this.Client.DefaultRequestHeaders.Add(header.Key, header.Value.ToString()); } } HttpResponseMessage response = null; if (method == HttpMethod.Get) { response = await this.Client.GetAsync(url); } else if (method == HttpMethod.Post) { response = await this.Client.PostAsync(url, payload); } else if (method == HttpMethod.Put) { response = await this.Client.PutAsync(url, payload); } else if (method == HttpMethod.Delete) { response = await this.Client.DeleteAsync(url); } if (response != null) { if (response.IsSuccessStatusCode) { return(new ResponseResult(response.StatusCode, string.Empty) { Data = await response.Content.ReadAsStringAsync() }); } else { return(new ResponseResult(response.StatusCode, await response.Content.ReadAsStringAsync())); } } else { return(new ResponseResult(false, "Response is null!")); } }