Esempio n. 1
0
        private static HttpClient CreateHttpClient(IAuthentication authentication, ConnectionInfo connectionInfo)
        {
            var handler = new HttpClientHandler
            {
                AllowAutoRedirect = connectionInfo.AllowAutoRedirect,
                UseProxy          = connectionInfo.UseProxy,
                Proxy             = connectionInfo.Proxy
            };

            var client = new HttpClient(handler, true)
            {
                BaseAddress = connectionInfo.Address
            };

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(HttpContentTypesHelper.Json));
            client.DefaultRequestHeaders.ExpectContinue = connectionInfo.ExpectContinue;

            if (connectionInfo.Timeout.HasValue)
            {
                client.Timeout = connectionInfo.Timeout.Value;
            }

            authentication.AddToHeaders(client);

            return(client);
        }