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))); }
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))); }