检测 IE 代理设置并与 TIdHTTP 一起使用
如何设置 TIdHTTP 以使用 IE 代理配置?
它应该兼容XP/Vista/Win7并且可靠。
How do I set TIdHTTP to use IE proxy configuration?
It should be compatible with XP/Vista/Win7 and reliable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Indy 不使用 Internet Explorer 的代理设置,因此您必须自己获取它,例如使用
InternetQueryOption
函数。更新:
这是使用
WinHTTP
应该尝试从 IE 接收设置。如果它们可用并且设置了自动检测代理设置或自动配置脚本 URL 选项,则将执行代理检测。当 IE 设置不可用时,也会执行自动检测。免责声明:
以下代码仅针对最简单的情况进行了测试,即 IE 设置可用且代理设置未配置为自动检测(不没有环境)。另请注意,本单元中的一些函数、结构和常量是附加的。
对于替代的 Delphi 代码,您可以查看例如
此提示
。以下是如何使用获取的代理设置设置
TIdHTTP
的示例(实际上,您只需解析获取的代理 URL 并将其传递到ProxyServer
和ProxyPort
属性):Indy doesn't use Internet Explorer's proxy settings and so you have to get it by yourself, for instance by using
InternetQueryOption
function.Update:
Here is the code using
WinHTTP
which should try to receive the settings from IE. If they are available and auto-detect proxy settings or auto-config script URL options are set, then the proxy detection will be performed. Auto-detection will also be performed when the IE settings are not available.Disclaimer:
The following code has been tested only for the easiest case, when the IE settings are available and the proxy settings are not configured to be detected automatically (don't have the environment). Also please note that some of the functions, structures and constant are additional in this unit.
For an alternative Delphi code you can check e.g.
this tip
.Here's an example of how to setup a
TIdHTTP
with obtained proxy settings (actually you just parse the obtained proxy URL and pass it to theProxyServer
andProxyPort
properties):您也可以通过 Windows 注册表获取它,如下所示:
You can get it also through Windows Registry as :