/// <summary> /// Creates and asynchronously sends an HttpRequestMethod, disposing HttpClient if AutoDispose it true. /// Mainly used to implement higher-level extension methods (GetJsonAsync, etc). /// </summary> /// <param name="verb">The HTTP method used to make the request.</param> /// <param name="content">Contents of the request body.</param> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional.</param> /// <param name="completionOption">The HttpCompletionOption used in the request. Optional.</param> /// <returns>A Task whose result is the received HttpResponseMessage.</returns> public async Task <HttpResponseMessage> SendAsync(HttpMethod verb, HttpContent content = null, CancellationToken?cancellationToken = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { try { var request = new HttpRequestMessage(verb, Url) { Content = content }; if (Settings.CookiesEnabled) { WriteRequestCookies(request); } HttpCall.Set(request, Settings); var resp = await HttpClient.SendAsync(request, completionOption, cancellationToken ?? CancellationToken.None).ConfigureAwait(false); if (Settings.CookiesEnabled) { ReadResponseCookies(resp); } return(resp); } finally { if (AutoDispose) { Dispose(); } } }
/// <summary> /// Creates and asynchronously sends an HttpRequestMethod, disposing HttpClient if AutoDispose it true. /// Mainly used to implement higher-level extension methods (GetJsonAsync, etc). /// </summary> /// <returns>A Task whose result is the received HttpResponseMessage.</returns> public async Task <HttpResponseMessage> SendAsync(HttpMethod verb, HttpContent content = null, CancellationToken?cancellationToken = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead) { try { var request = new HttpRequestMessage(verb, this.Url) { Content = content }; HttpCall.Set(request, this.Settings); return(await HttpClient.SendAsync(request, completionOption, cancellationToken ?? CancellationToken.None).ConfigureAwait(false)); } finally { if (AutoDispose) { Dispose(); } } }