tags:

views:

2017

answers:

1

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?

+2  A: 

HttpWebRequest.Proxy returns an IWebProxy interface, not WebProxy. 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.

adrianbanks