Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect proxy settings of default web browser

Tags:

c#

proxy

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?

like image 362
Sameet Avatar asked Jun 21 '09 10:06

Sameet


1 Answers

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.

like image 65
adrianbanks Avatar answered Oct 02 '22 13:10

adrianbanks