Using proxy servers in your C# applications.
This code snippet will show you how to use a proxy server in conjunction with the WebClient class. I’m pretty sure the WebClient class automatically uses your IE configuration (correct me if I’m wrong). This is helpful for those that are developing C# in Linux, but are behind an annoying corporate proxy server.
private string downloadURL( string url )
{
WebProxy p = null;
ICredentials cred;
cred = new NetworkCredential("myUserName", "myPasword");
p = new WebProxy("inet1.someproxy.com:80", true, null, cred);
WebRequest.DefaultWebProxy = p;
WebClient wc = new WebClient();
wc.Proxy = p;
string data = wc.DownloadString(url);
return data;
}



No Comments »
No comments yet.
RSS feed for comments on this post. TrackBack URL
Leave a comment