检测默认Web浏览器的代理服务器设置 [英] Detect proxy settings of default web browser
本文介绍了检测默认Web浏览器的代理服务器设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
MSDN样本
HttpWebRequest的myWebRequest =(HttpWebRequest的)WebRequest.Create(http://www.microsoft.com );
WebProxy MYPROXY =新WebProxy();
//获取默认浏览器的代理。
MYPROXY =(WebProxy)myWebRequest.Proxy;
不工作。
错误我得到的是:无法投类型的对象WebProxyWrapper为键入'System.Net.WebProxy
做什么选择我? / p>
解决方案
的HttpWebRequest.Proxy
返回的 IWebProxy
接口,而不是 WebProxy
。改变这种状况,也将努力。
您还可以使用的 WebRequest.DefaultWebProxy 或的WebRequest。 GetSystemWebProxy()获得,而不是作出的HttpWebRequest
并获得从该代理。
代理详细信息
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 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.
这篇关于检测默认Web浏览器的代理服务器设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文