コード例 #1
0
        public bool EnableProxy(string proxy, string[] exceptions,
                                string user, string pass)
        {
            IWebProxy defaultWebProxy = WebRequest.DefaultWebProxy;
            IWebProxy systemWebProxy  = WebRequest.GetSystemWebProxy();

            CredentialCache credentials = new CredentialCache();

            SecureString securePass = new SecureString();

            foreach (char c in pass)
            {
                securePass.AppendChar(c);
            }
            securePass.MakeReadOnly();

            NetworkCredential networkCredential = new NetworkCredential(user, securePass);

            credentials.Add(new Uri(proxy), AUTHENTICATION_TYPE_DIGEST, networkCredential);

            IWebProxy myProxy = new WebProxy(proxy, true, exceptions, credentials);

            WebRequest.DefaultWebProxy = myProxy;
            systemWebProxy.Credentials = myProxy.Credentials;

            return(SystemProxySettings.SetProxy(proxy,
                                                String.Join(";", exceptions)));
        }
コード例 #2
0
        public bool EnableProxy(string proxy, string[] exceptions)
        {
            IWebProxy defaultWebProxy = WebRequest.DefaultWebProxy;
            IWebProxy systemWebProxy  = WebRequest.GetSystemWebProxy();

            IWebProxy myProxy = new WebProxy(proxy, true, exceptions);

            WebRequest.DefaultWebProxy = myProxy;

            return(SystemProxySettings.SetProxy(proxy,
                                                String.Join(";", exceptions)));
        }
コード例 #3
0
 public bool IsProxyEnabled()
 {
     return(SystemProxySettings.GetProxyEnabled());
 }
コード例 #4
0
 public bool DisableProxy()
 {
     WebRequest.GetSystemWebProxy().Credentials = null;
     WebRequest.DefaultWebProxy = null;
     return(SystemProxySettings.UnsetProxy());
 }