Пример #1
0
        /// <summary>
        /// Initializes a new instance of the WebApiClient class.
        /// </summary>
        /// <param name="clientParameters">Custom WebAPI Client parameters</param>
        public WebApiClient(WebApiClientParameters clientParameters)
        {
            this.clientParameters = clientParameters;

            this.webRequestHandler = new WebRequestHandler();
            if (clientParameters.Certificate != null)
            {
                this.webRequestHandler.ClientCertificates.Add(clientParameters.Certificate);
            }

            this.messageHandler = new WebApiOutgoingRequestHandler(this.webRequestHandler, clientParameters);
            this.httpClient     = CreateHttpClient(clientParameters, this.messageHandler);
        }
Пример #2
0
        private static HttpClient CreateHttpClient(WebApiClientParameters clientParameters, MessageProcessingHandler handler)
        {
            var httpClient = new HttpClient(handler)
            {
                // MaxResponseContentBufferSize = clientParameters.MaxResponseContentBufferSizeInBytes,
                // Timeout = clientParameters.HttpClientTimeout
            };

            httpClient.DefaultRequestHeaders.Remove(HttpRequestHeader.Authorization.ToString());
            var mediaTypeWithQualityHeaderValue = new MediaTypeWithQualityHeaderValue(clientParameters.MediaType);

            httpClient.DefaultRequestHeaders.Accept.Add(mediaTypeWithQualityHeaderValue);

            // httpClient.DefaultRequestHeaders.Add(HeaderConstants.XmsVersion, clientParameters.Headers.Version);

            return(httpClient);
        }
 public WebApiOutgoingRequestHandler(HttpMessageHandler handler, WebApiClientParameters parameters = null)
     : base(handler)
 {
     this.parameters = parameters;
 }