CmisSync.Lib.HttpProxyUtils.SetDefaultProxy C# (CSharp) Method

SetDefaultProxy() public static method

Sets the default proxy for every HTTP request. If the caller would like to know if the call throws any exception, the second parameter should be set to true
public static SetDefaultProxy ( Config settings, bool throwExceptions = false ) : void
settings Config proxy settings.
throwExceptions bool If set to true throw exceptions.
return void
        public static void SetDefaultProxy(Config.ProxySettings settings, bool throwExceptions = false)
        {
            try
            {
                IWebProxy proxy = null;
                switch(settings.Selection) {
                    case Config.ProxySelection.SYSTEM:
                        proxy = WebRequest.GetSystemWebProxy();
                        break;
                    case Config.ProxySelection.CUSTOM:
                        proxy = new WebProxy(settings.Server);
                        break;
                }

                if (settings.LoginRequired && proxy != null) {
                    proxy.Credentials = new NetworkCredential(settings.Username, Crypto.Deobfuscate(settings.ObfuscatedPassword));
                }

                WebRequest.DefaultWebProxy = proxy;
            }
            catch (Exception e)
            {
                if (throwExceptions) {
                    throw;
                }

                Logger.Warn("Failed to set the default proxy, please check your proxy config: ", e);
            }
        }
    }
HttpProxyUtils