Beispiel #1
0
        /// <summary>
        /// Returns a WebProxy instance configured to match the proxy settings
        /// in the client configuration.
        /// </summary>
        public WebProxy GetWebProxy()
        {
            const string httpPrefix = "http://";

            WebProxy proxy = null;

            if (!string.IsNullOrEmpty(ProxyHost) && ProxyPort > 0)
            {
                // WebProxy constructor adds the http:// prefix, but doesn't
                // account for cases where it's already present which leads to
                // malformed addresses
                var host = ProxyHost.StartsWith(httpPrefix, StringComparison.OrdinalIgnoreCase)
                               ? ProxyHost.Substring(httpPrefix.Length)
                               : ProxyHost;
                proxy = new WebProxy(host, ProxyPort);

                if (ProxyCredentials != null)
                {
                    proxy.Credentials = ProxyCredentials;
                }
                if (ProxyBypassList != null)
                {
                    proxy.BypassList = ProxyBypassList.ToArray();
                }
                proxy.BypassProxyOnLocal = ProxyBypassOnLocal;
            }

            return(proxy);
        }
Beispiel #2
0
        public WebProxy GetWebProxy()
        {
            WebProxy webProxy = null;

            if (!string.IsNullOrEmpty(ProxyHost) && ProxyPort > 0)
            {
                webProxy = new WebProxy(ProxyHost.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ? ProxyHost.Substring("http://".Length) : ProxyHost, ProxyPort);
                if (ProxyCredentials != null)
                {
                    webProxy.Credentials = ProxyCredentials;
                }
                if (ProxyBypassList != null)
                {
                    webProxy.BypassList = ProxyBypassList.ToArray();
                }
                webProxy.BypassProxyOnLocal = ProxyBypassOnLocal;
            }
            return(webProxy);
        }