禁用 WebClient 自动代理检测
我在 DownloadStringAsync 调用速度相当慢时遇到困难。我发现(在这个问题中)这是由于自动代理检测造成的。
显然,可以通过将 WebClient 的 Proxy 属性设置为 null 来关闭自动检测。
有没有什么情况会导致问题?我对代理不太熟悉,但是如果用户出于某种原因需要代理来访问网络,这会失败吗?
一些背景:此调用是在更新管理器中进行的。它从我控制的服务器上抓取一个文件,以查看程序是否需要更新。因此,这并不完全重要,但如果它能够为大多数用户工作那就太好了。
I was having difficulties surrounding a DownloadStringAsync call being rather slow. I found (in this question) that this is due to Automatic Proxy Detection.
Apparently, the auto detection can be turned off by setting the WebClient's Proxy property to null.
Is there any case when this could cause problems? I'm not too familiar with proxies, but if the user for some reason needs a proxy to access the web, will this fail?
Some background: this call is in an update manager. It's grabbing a file from a server I control to see whether the program needs to update. So, not completely crucial, but it would be nice to have it work for most users.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您正在编写一个应该在所有环境中运行的应用程序,则不要关闭自动代理检测。否则,您就会敞开心扉接受支持电话。
相反,默认情况下会启用自动代理检测,并允许用户更改它,以使用显式代理,或者根据需要禁用代理。
查看 Internet Explorer 连接设置 UI 的示例。
If you are writing an app that is supposed to run in all environments, then do not switch off autoproxy detection. Otherwise you are opening yourself up to support calls.
Instead, ship with autoproxy detection on by default, and allow the users to change that, to use an explicit proxy, or disable proxy if they so want.
look at the Internet Explorer connection settings UI for an example.