不依赖于Auto-Config文件的代理发现
If a proxy auto-configuration file has not been deployed on the local network,WinHttpGetProxyForUrl cannot find a proxy server. If WinHttpGetProxyForUrl fails, there are several possible fall-back strategies for obtaining a viable proxy configuration, depending on its runtime environment. These include prompting for the proxy setting through a user interface, requiring someone to store the proxy configuration in the registry using the WinHTTP "ProxyCfg.exe" utility, or usingWinHttpGetIEProxyConfigForCurrentUser to check whether a proxy server is listed in Internet Explorer's settings.
如果本地网络压根就没部署PAC文件,WinHttpGetProxyForUrl就找不到代理服务器。如果WinHttpGetProxyForUrl失败了,还有几种可能获取可用代理配置的回跳策略,这就要看它所运行的环境如何。这包括通过用户界面设置代理,要求用户使用WinHTTP "ProxyCfg.exe"工具存储代理在注册表,或使用WinHttpGetIEProxyConfigForCurrentUser来检查IE代理设置。
It is possible that there is no proxy auto-configuration file because the client has a direct Internet connection, such as through an ISP, and does not need a proxy server.
有可能本来就没有代理PAC文件,因为用户有直连到Internet的连接,比如通过ISP,这就不需要代理服务器。
A proxy server may be required, on the other hand, but the local network may not support WPAD. In this case, the proxy configuration must be obtained from the user or found somewhere on the client machine.
有时候也要代理服务器,但另一方面,本地网络又不支持WPAD。这种情况,代理配置必须从用户获取或者是从用户存储在本地某个位置上获取。
A WinHTTP-based application running in a middle-tier server environment, such as a COM+ or ASP application, should rely on a server administrator setting a default proxy configuration in the registry using the "ProxyCfg.exe" utility. This default configuration information can then be retrieved either by using the WinHttpGetDefaultProxyConfiguration function, or simply by specifying theWINHTTP_ACCESS_TYPE_PRECONFIG flag in theWinHttpOpen call.
一个运行在中间层的基于WinHTTP的程序,比如一个COM+或ASP程序,要依靠服务器管理员使用ProxyCfg.exe工具在注册表中设置一个默认代理配置。这中默认配置信息然后就可以使用WinHttpGetDefaultProxyConfiguration从注册表中获取,或只需简单指定WinHttpOpen函数中的WINHTTP_ACCESS_TYPE_PRECONFIG标志。
On the other hand, a WinHTTP application running on a client desktop machine can attempt to examine Internet Explorer's proxy settings.WinHttpGetIEProxyConfigForCurrentUser fills in a caller-suppliedWINHTTP_CURRENT_USER_IE_PROXY_CONFIG structure with the current user's Internet Explorer proxy settings for the current active connection (dial-up, VPN or LAN). This configuration may indicate that auto-detection is used, or it may specify a URL for a proxy auto-configuration file, or it may specify an actual proxy server to use, or it may specify a combination of the three. If this information includes a PAC URL or a proxy server, the WinHTTP application can try using those.
另外,一个运行于客户桌面机器的WinHTTP程序可以尝试测试IE代理设置。WinHttpGetIEProxyConfigForCurrentUser填入用户提供的的WINHTTP_CURRENT_USER_IE_PROXY_CONFIG结构体,这个结构体中已经指定了当前用户活动连接(dial-up, VPN or LAN)的IE代理设置。这个配置也可以指明自动探测是否被使用,或这指定了一个URL来获取PAC文件,或指定使用一个真实的代理服务器,或指定结合使用上述三种方式。如果这个信息包含PAC URL或是代理服务器,WinHTTP程序可以尝试使用这些信息。
A sample that uses the WinHttpGetProxyForUrl and WinHttpGetIEProxyConfigForCurrentUser functions can be found in the Platform Software Development Kit (SDK) WinHTTP samples.
一个使用WinHttpGetProxyForUrl 和WinHttpGetIEProxyConfigForCurrentUser函数的例子可以在Platform Software Development Kit (SDK) WinHTTP中找到。