【发布时间】:2014-02-21 23:59:53
【问题描述】:
我想以编程方式(C#)获取在“IE -> Lan Settings”中设置的代理,我使用了来自stackoverflow question的以下代码
WebProxy proxy = (WebProxy) WebRequest.DefaultWebProxy;
但问题是我得到以下异常:-
无法投射“System.Net.WebRequest.DefaultWebProxy”(它有一个 'System.Net.WebRequest.WebProxyWrapper'的实际类型) 'System.Net.WebProxy'
那么如何获取 WebProxy 对象以便检查代理是否设置?
编辑:
我搞定了;我只需要知道是否绕过了特定的网址,所以我这样做了
Uri rpkgURI = new Uri("%url%", UriKind.RelativeOrAbsolute);
IWebProxy webProxy = WebRequest.GetSystemWebProxy();
bool isBypass;
if (webProxy != null)
{
isBypass = webProxy.IsBypassed(rpkgURI);
}
else
{
isBypass = true;
}
【问题讨论】:
标签: c# networking proxy