Tuesday, May 20, 2008

How to find IE proxy settings with Visual Studio C#?

In many cases of programming stuff that works with internet, it would be handy to know what are the proxy settings that Internet Explorer uses.

How to find proxy settings with Visual Studio C#? Here is the answer...

private static void CheckForProxy(Uri resource)

{

WebProxy proxy = (WebProxy)WebProxy.GetDefaultProxy();

Uri proxyUri = proxy.GetProxy(resource);

if (proxyUri == resource)

{

MessageBox.Show("No proxy for " + resource);

}

else

{

MessageBox.Show("Proxy for " + resource + " is " + proxyUri.ToString());

}

}

This code allows you to find out what proxy uses for each type of Uri.

Pass any server address for Uri parameter as a Uri object.

Example: ProxyCheck(new Uri("http://64.202.189.170"));

Note: This uses System.net namespace. Don't forget! :)

No comments: