A shortcut to build a web proxy

31. July 2008

For reusing : 

public static WebProxy BuildProxy(string proxyServer, int proxyPort, string login, string password, string commaSeparatedProxyExclusions)
{
    WebProxy proxy = new WebProxy(proxyServer, proxyPort);     if (!String.IsNullOrEmpty(login))
    {
        NetworkCredential proxyCredential = new NetworkCredential(login, password);
        CredentialCache proxyCredentials = new CredentialCache();

        proxyCredentials.Add(proxy.Address,
"Basic", proxyCredential);
        proxyCredentials.Add(proxy.Address,
"Digest", proxyCredential);
        proxy.Credentials = proxyCredentials;
    }

    foreach (string exclude in commaSeparatedProxyExclusions.Split(new char[] { ',' }))
    if (!String.IsNullOrEmpty(exclude)) proxy.BypassArrayList.Add(exclude.Trim());

    proxy.BypassProxyOnLocal =
true;

    return proxy;
}

C# sample code

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading