public async Task <WebClientResponseMessage> PatchAsync(WebClientRequestMessage request, CancellationToken cancellationToken = default(CancellationToken)) { var httpRequestMessage = await CreateHttpRequestMessage(request, new System.Net.Http.HttpMethod(Constants.HttpMethod.PATCH)); var result = await _httpClient.SendAsync(httpRequestMessage, cancellationToken); return(await CreateWebClientResponseMessage(result)); }
public async Task <IResponse <T> > GetAsync <T>(WebGetRequest request) { WebClientResponseMessage postResponse = null; WebResponse <T> response = default(WebResponse <T>); var serializeSettings = GetSerializerSettings(request.SerializerSettings); var startTimestamp = DateTime.UtcNow; var watch = new Stopwatch(); var clientSettings = GetClientSettings(request.ClientSetting); try { new RequestValidator().Validate(request); try { var webClientRequest = new WebClientRequestMessage() { Url = request.EndPoint.Url }; foreach (var headerName in clientSettings.Headers.AllKeys) { webClientRequest.RequestHeaders.Add(headerName, clientSettings.Headers[headerName]); } webClientRequest.ContentHeaders.Add("content-type", clientSettings.ContentType); watch.Start(); postResponse = await _client.GetAsync(webClientRequest, clientSettings, new CancellationToken()); watch.Stop(); } catch (Exception exception) { if (watch.IsRunning) { watch.Stop(); } throw new ClientCommunicationException(request.EndPoint, exception); } response = GetResponse <T>(postResponse, serializeSettings); } finally { if (watch.IsRunning) { watch.Stop(); } var url = string.Empty; if (request.EndPoint != null) { url = request.EndPoint.Url; } await Log(postResponse, null, url, response, watch.ElapsedMilliseconds, clientSettings, url, startTimestamp); } return(response); }
private static async Task <HttpRequestMessage> CreateHttpRequestMessage(WebClientRequestMessage message, System.Net.Http.HttpMethod httpMethod) { var httpRequestMessage = new HttpRequestMessage(httpMethod, message.Url); httpRequestMessage.Content = await message.GetHttpContentAsync(); foreach (var key in message.RequestHeaders.AllKeys) { httpRequestMessage.Headers.Add(key, message.RequestHeaders[key]); } return(httpRequestMessage); }
public static async Task <WebClientResponseMessage> DeleteAsync(this IWebClient client, WebClientRequestMessage request) { return(await client.DeleteAsync(request, CancellationToken.None)); }