MSDN sample
HttpWebRequest myWebRequest=(HttpWebRequest)WebRequest.Create("http://www.microsoft.com");
WebProxy myProxy=new WebProxy();
// Obtain the 'Proxy' of the Default browser.
myProxy=(WebProxy)myWebRequest.Proxy;
Doesn't work. The error I get is: Unable to cast object of type 'WebProxyWrapper' to type 'System.Net.WebProxy'
What options do I have?
HttpWebRequest.Proxy
returns anIWebProxy
interface, notWebProxy
. Change that and it will work.You can also use WebRequest.DefaultWebProxy or WebRequest.GetSystemWebProxy() to get the proxy details instead of making an
HttpWebRequest
and getting the proxy from that.To check automatically detect setting, use code: