internal WebProxy GetWebProxy() { const string httpPrefix = "http://"; WebProxy proxy = null; if (!string.IsNullOrEmpty(Hostname) && Port > 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 = Hostname.StartsWith(httpPrefix, StringComparison.OrdinalIgnoreCase) ? Hostname.Substring(httpPrefix.Length) : Hostname; proxy = new WebProxy(host, Port); if (Credentials != null) { proxy.Credentials = Credentials; } if (BypassList != null) { proxy.BypassList = BypassList.ToArray(); } if (BypassOnLocal.HasValue) { proxy.BypassProxyOnLocal = BypassOnLocal.Value; } } return(proxy); }
public WebProxy ToWebProxy() { if (!Enabled || String.IsNullOrEmpty(Host)) { return(null); } int port = Int32.Parse(Port); WebProxy wp = new WebProxy(Host, port); wp.BypassProxyOnLocal = BypassLocal; if (!String.IsNullOrEmpty(BypassList)) { wp.BypassList = BypassList.Split(';'); } if (!String.IsNullOrEmpty(User)) { wp.Credentials = new NetworkCredential(User, Password); } return(wp); }