我遇到.NET检测通过Internet Explorer配置的代理设置的问题.
我正在编写一个支持代理的客户端应用程序,并测试我设置了一个包含9个squid服务器的数组,以支持HTTP和HTTP的各种身份验证方法.我有一个脚本,可以将IE更新为我选择的任何配置(哪个代理,通过"自动",PAC或硬编码进行检测).
我已经尝试了以下3种方法来通过.NET检测IE配置.在我看来,我发现.NET选择了错误的代理服务器集.IE具有正确的设置,如果我使用IE浏览网页,我可以看到我通过wireshark访问正确的服务器.
WebRequest.GetSystemWebProxy().GetProxy(destination);
GlobalProxySelection.Select.GetProxy(destination);
WebRequest.DefaultWebProxy
以下是我的提示:
我找到了解决方案。
.NET 使用“WinHttp Web 代理自动发现服务”来执行 PAC 脚本,并可能缓存结果。只需停止并重新启动此服务即可解决问题。以下命令行为我执行此操作。
NET STOP WinHttpAutoProxySvc
NET START WinHttpAutoProxySvc
Run Code Online (Sandbox Code Playgroud)
http://wiki.blackviper.com/wiki/WinHTTP_Web_Proxy_Auto-Discovery_Service
我按照 James Kovacs 附加调试器的建议发现了这一点。在我发布问题之前,我已经通过代码进行了反思,并尝试附加调试器失败,但无法准确解读发生了什么。用完选项后,我再次尝试调试,几个小时后在 _AutoPWebProxyScriptEngine.cs 第 76 行中找到了以下注释,这使我发现了这一点
// In Win2003 winhttp added a Windows Service handling the auto-proxy discovery. In XP using winhttp
// APIs will load, compile and execute the wpad file in-process. This will also load COM, since
// WinHttp requires COM to compile the file. For these reasons, we don't use WinHttp on XP, but
// only on newer OS versions where the "WinHTTP Web Proxy Auto-Discovery Service" exists.
Run Code Online (Sandbox Code Playgroud)