blog.devbroker.org author="Patrick Rabian" about="c#, sharepoint, biztalk, team system resources" more="news, samples, tips for .NET world's developers !"

A shortcut to build a web proxy

Wednesday, 30 July 2008 18:07 by prabian

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

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:  
Categories:   C# sample code
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

September 6. 2008 01:45