C# auto detect proxy settings

It appears that WebRequest.DefaultWebProxy is the official replacement for WebProxy.GetDefaultProxy.

You should be able to drop that in to your original code with only a little modification. Something like:

WebProxy proxy = (WebProxy) WebRequest.DefaultWebProxy;
if (proxy.Address.AbsoluteUri != string.Empty)
{
    Console.WriteLine("Proxy URL: " + proxy.Address.AbsoluteUri);
    wc.Proxy = proxy;
}

First, GetDefaultProxy is marked as deprecated so you have no guarantee it will be around in even the immediate future. Second, Address can be null so the code you gave risks a NullReferenceException:


WebClient etc use the WinHTTP settings (not the IE settings), so the easiest thing to do is to configure WinHTTP! On XP etc you can use:

proxycfg -u

to import the current IE settings into the WinHTTP store. After that, WebClient etc should be able to use the same settings without issue. On Vista and Windows 7 this is now found under:

netsh winhttp import proxy ie

You need to run this as administrator.