public async Task <HttpResponseMessage> ExecuteAsync( HttpClientServiceRequest model) { using (var client = _getClient()) { var requestMessage = new HttpRequestMessage { Method = model.Method, RequestUri = new Uri(model.UriString) }; foreach (var header in model.Headers) { requestMessage.Headers.Add(header.Key, header.Value); } if (model.Content != null) { requestMessage.Content = new ObjectContent( model.Content.GetType(), model.Content, _mediaTypeFormatter); } return(await client.SendAsync(requestMessage)); } }
public static async Task <HttpServiceResponse> ExecuteAndReadAsync( this IHttpClientService client, HttpClientServiceRequest request ) { var responseMessage = await client.ExecuteAsync(request); var serviceResponse = await ReadAsync( HttpServiceResponse.Empty, responseMessage); return(serviceResponse); }
public static async Task <HttpServiceResponse <T> > ExecuteAndReadAsync <T>( this IHttpClientService client, HttpClientServiceRequest request ) { var responseMessage = await client.ExecuteAsync(request); var serviceResponse = await ReadAsync( HttpServiceResponse <T> .Empty, responseMessage); serviceResponse = serviceResponse .WithData( await responseMessage.Content.ReadAsAsync <T>() ); return(serviceResponse ); }