Пример #1
0
        private static WebRequest CreateWebRequest(string url, IProxyConfig proxyConfig = null)
        {
            WebRequest webRequest = WebRequest.Create(url);

            AddDefaultHeaders(webRequest);
            webRequest.Method  = HttpMethod.Head.Method;
            webRequest.Proxy   = proxyConfig?.CreateWebProxy();
            webRequest.Timeout = 10000;

            return(webRequest);
        }
Пример #2
0
        public static HttpClientHandler CreateHttpClientHandler([CanBeNull] IProxyConfig proxyConfig)
        {
            HttpClientHandler clientHandler = new HttpClientHandler
            {
                PreAuthenticate       = false,
                UseDefaultCredentials = true,
                UseProxy = false
            };

            if (proxyConfig?.IsValid() == true)
            {
                IWebProxy proxy = proxyConfig.CreateWebProxy();
                if (proxy != null)
                {
                    clientHandler.UseProxy = true;
                    clientHandler.Proxy    = proxy;
                    clientHandler.UseDefaultCredentials = proxyConfig.UseDefaultCredentials;
                    clientHandler.PreAuthenticate       = proxyConfig.UseDefaultCredentials;
                }
            }

            return(clientHandler);
        }