private async Task <HttpResponseMessage> GetHttpResponseMessage([NotNull] BaiduRestRequest restRequest, CancellationToken cancellationToken = default(CancellationToken)) { _client = new HttpClient(); var message = new HttpRequestMessage(restRequest.Method, restRequest.GetUri()); return(await _client.SendAsync(message, cancellationToken).ConfigureAwait(false)); }
public BaiduRestResponse([NotNull] BaiduRestRequest request, [NotNull] HttpResponseMessage responseMessage, Exception exception) : this() { this.Request = request; this.ResponseMessage = responseMessage; this.Exception = exception; }
public BaiduRestResponse([NotNull] BaiduRestRequest request, [NotNull] HttpResponseMessage responseMessage, string content) : this() { this.Request = request; this.ResponseMessage = responseMessage; this.Content = content; }
/// <summary> /// Execute request. /// </summary> /// <param name="request"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <BaiduRestResponse> SendAsync([NotNull] BaiduRestRequest request, CancellationToken cancellationToken = default(CancellationToken)) { BaiduRestResponse response = null; BaiduRestService.GetService(this).SendRequest(request); try { HttpResponseMessage httpResponseMessage = await GetHttpResponseMessage(request, cancellationToken).ConfigureAwait(false); string content = await GetResponseContent(httpResponseMessage).ConfigureAwait(false); response = new BaiduRestResponse(request, httpResponseMessage, content); } catch (Exception ex) { response = new BaiduRestResponse(request, new HttpResponseMessage(HttpStatusCode.BadRequest), ex); } finally { BaiduRestService.GetService(this).SendResponse(response); } return(response); }