Home > Programming > Using proxy servers in your C# applications.

Using proxy servers in your C# applications.

December 5th, 2009 Jimmy Leave a comment Go to comments

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;
		}
Digg: DIGG ME
  1. No comments yet.
  1. No trackbacks yet.