在WinHTTP中设置WinINet 代理配置
2015-05-14 08:40
393 查看
在WinHTTP中设置WinINet 代理配置
Setting Automatic Proxy on WinHTTP 5.1
在WinHTTP 5.1中设置Automatic ProxyApplications that port from WinINet to WinHTTP may need to use the same autoproxy settings that they can retrieve under WinINet or Internet Explorer (IE). The WinHTTP version 5.1 API can retrieve and use these proxy settings. In general, WinHTTP specifies
the proxy and proxy bypass servers on a per-session basis when the session is created. These settings can be overridden on a per-request basis.
从WinINet 向 WinHTTP迁移的程序可能需要使用相同的autoproxy设置,它们可以在WinINet下获取或从IE设置里面获取。WinHTTP 5.1 API可以获取和使用这些代理设置.一般情况下,WinHTTP在会话创建后就要为每次请求指定是使用代理或不使用代理。这些设置可以在每次访问设置的基础上重设。
To use the same proxy configuration as WinINet or IE, the WinHTTP client should set proxy settings for the session. In addition, if IE or WinINet are configured to use Web Proxy Auto-Discovery (WPAD), the WinHTTP client that uses those settings must set
proxy settings on a per-request basis. The following sections describe how to specify the proxy settings for a session and a request:
要使用和WinINet 或IE相同的代理设置,WinHTTP客户应该为会话设置代理设置。此外如果IE 或WinINet设置为使用WPAD,那么WinHTTP客户端如果要使用它们需要每次都要做设定。下列章节描述了如何为会话和请求指定代理。
Setting the Proxy Configuration on a Session
Setting the Proxy Configuration on a Single Request
Setting the Proxy Configuration on a Session
为会话指定代理The Application is Running on a User Account
程序运行于用户帐户下Before a session is created, the application calls
WinHttpGetIEProxyConfigForCurrentUser to get the IE proxy settings. The application must be running as a user account to obtain these settings. ThepProxyConfig parameter is a pointer to a
WINHTTP_CURRENT_USER_IE_PROXY_CONFIG structure that contains the proxy name (lpszProxy) and proxy bypass (lpszProxyBypass) servers. The proxy name and proxy bypass values of theWINHTTP_CURRENT_USER_IE_PROXY_CONFIG
structure are then used to initialize the WinHTTP session. The session is initialized by callingWinHttpOpen with the
pwszProxyName and pwszProxyBypass parameters obtained from thelpszProxy and
lpszProxyBypass members of the WINHTTP_CURRENT_USER_IE_PROXY_CONFIG structure.
在会话被创建前,程序调用WinHttpGetIEProxyConfigForCurrentUser获取IE代理设置。程序必须以用户帐户状体来获取这些设置。pProxyConfig参数是一个指向WINHTTP_CURRENT_USER_IE_PROXY_CONFIG结构体的指针,这个结构体包含代理名称(lpszProxy)
和不使用代理的目标 (lpszProxyBypass) 。然后使用设好参数的WINHTTP_CURRENT_USER_IE_PROXY_CONFIG结构体初始化WinHTTP会话。调用WinHttpOpen初始化会话,pwszProxyName
和pwszProxyBypass 参数分别从WINHTTP_CURRENT_USER_IE_PROXY_CONFIG结构体中的lpszProxy 和lpszProxyBypass中获取。
The Application is Running as a Service
程序以服务形式运行The application must ensure that the registry settings for an individual user are loaded into the registry before callingWinHttpGetIEProxyConfigForCurrentUser.
If these settings are not loaded into the registry,WinHttpGetIEProxyConfigForCurrentUser cannot obtain the proxy settings. Registry settings for an individual user can be loaded into the registry by calling theLoadUserProfile
function. If loading the user's registry settings is not an option, the application can callWinHttpOpen with the
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY specified in thedwAcessType parameter. Specifying the default proxy in the call to
WinHttpOpen tells the WinHTTP API to retrieve the proxy configuration set by using the WinHTTPproxycfg.exe utility.
After the registry settings for an individual user have been loaded, the application follows the steps outlined underThe
application is running on a user account to set the proxy name and proxy bypass servers.
程序必须保证在调用WinHttpGetIEProxyConfigForCurrentUser前把用户的注册表设置被加载到注册表。如果这些设置没有被加载到注册表,那么WinHttpGetIEProxyConfigForCurrentUser不能获取代理设置。加载用户注册表可以通过调用LoadUserProfile实现。如果调用用户注册表不能用,程序可以在调用WinHttpOpen函数时使用WINHTTP_ACCESS_TYPE_DEFAULT_PROXY指定dwAcessType参数。这样设置是告诉WinHTTP
API使用proxycfg.exe获取代理配置。在用户注册表被加载后,程序使用The
application is running on a user account章节中的步骤来获取代理名称和不使用代理服务器的目标。
Setting the Proxy Configuration on a Single Request
在一次代理请求中配置代理服务器配置Before the session is created, the application calls
WinHttpGetIEProxyConfigForCurrentUser to determine if WinINet and IE are configured to use WPAD.WinHttpGetIEProxyConfigForCurrentUser returns the
WINHTTP_CURRENT_USER_IE_PROXY_CONFIG structure that contains thefAutoDetect member. A value of
TRUE for this member indicates that WPAD is used, and thelpszAutoConfigUrl member contains the WPAD URL.
在会话被创建前,程序调用WinHttpGetIEProxyConfigForCurrentUser函数确定WinINet 和IE是否配置为WPAD。WinHttpGetIEProxyConfigForCurrentUser返回WINHTTP_CURRENT_USER_IE_PROXY_CONFIG结构体,结构体中包含fAutoDetect成员,这个成员设为TURE时表示WPAD可以使用,lpszAutoConfigUrl包含了WPAD
URL。
Automatic Proxy Configuration Is Used
应用了Automatic Proxy 配置
If WPAD is used, the application callsWinHttpGetProxyForUrl to retrieve the proxy for the request. ThelpwszUrl parameter contains the URL that the request is being sent to, and thepAutoProxyOptions parameter contains a pointer to the structure (WINHTTP_AUTOPROXY_OPTIONS)
that contains the autoproxy options. The application initializes the WINHTTP_AUTOPROXY_OPTIONS structure with the settings returned from theWINHTTP_CURRENT_USER_IE_PROXY_CONFIG
structure in the call toWinHttpGetIEProxyConfigForCurrentUser. The
WINHTTP_AUTOPROXY_CONFIG_URL flag is specified in thedwFlags member of the
WINHTTP_AUTOPROXY_OPTIONS structure, and thelpszAutoconfigUrl member contains the proxy auto-configuration URL from theWINHTTP_CURRENT_USER_IE_PROXY_CONFIG structure. The
WinHttpGetProxyForUrl function returns the proxy name and the proxy bypass list in thelpszProxy and
lpszProxyBypass members of the
WINHTTP_PROXY_INFO structure.
如果使用了WPAD,程序调用WinHttpGetProxyForUrl来为请求获取代理。lpwszUrl参数包含URL目标,pAutoProxyOptions参数指向一个结构体(WINHTTP_AUTOPROXY_OPTIONS,这个结构体中包含自动代理设置)。程序使用WinHttpGetIEProxyConfigForCurrentUser函数返回的WINHTTP_CURRENT_USER_IE_PROXY_CONFIG结构体初始化WINHTTP_AUTOPROXY_OPTIONS结构体。WinHttpGetProxyForUrl函数返回WINHTTP_PROXY_INFO结构体,结构体在lpszProxy
和lpszProxyBypass成员中包含代理名称和绕过代理设置。
After the proxy for the request is obtained from
WinHttpGetProxyForUrl, the application creates the request withWinHttpOpenRequest. Then
WinHttpSetOption is called to set the proxy for the request by specifying the request handle in thehInternet parameter. The
dwOption parameter in the call to WinHttpSetOption should be set to
WINHTTP_OPTION_PROXY and thelpBuffer parameter is a pointer to a
WINHTTP_PROXY_INFO structure that contains the proxy and proxy bypass to be used for the request.
在使用WinHttpGetProxyForUrl获取请求代理后,程序使用WinHttpOpenRequest创建请求。然后调用WinHttpSetOption为请求设置代理,方法是在hInternet参数中设定请求句柄。WinHttpSetOption中的dwOption参数可以设定为WINHTTP_OPTION_PROXY,lpBuffer参数是一个指向WINHTTP_PROXY_INFO结构体的指针,这个机构体中有代理服务器和不使用代理服务器的设置。
Automatic Proxy Configuration Is Not Used
没有使用Automatic Proxy配置If the call to
WinHttpGetIEProxyConfigForCurrentUser indicates that autoproxy is not used, the application can simply create the request withWinHttpOpenRequest.
The proxy configuration is the same for the entire session, and per-request changes are not needed.
如果调用WinHttpGetIEProxyConfigForCurrentUser后发现没用autoproxy,程序就可以简单调用WinHttpOpenRequest创建请求。代理配置就和整个会话一致,每次都去设置这种情况就不需要了。
相关文章推荐
- 配置 WinHTTP 的代理设置
- 配置 WinHTTP 的代理设置
- WinInet 与 winHTTP 共同在代码文件中引用会引起编译错误
- WinInet, WinHttp, Winsock, ws2_32的区别和联系
- java模拟http的Get/Post请求,并设置ip与port代理
- SVN-1.5.3+Apache-2.0.59在windows下的配置与权限设置,以及配置HTTP方式访问SVN服务器
- wininet、winhttp、winsock的区别
- Maven的HTTP代理设置
- 使用WinINet和WinHTTP实现Http访问
- Tomcat配置https协议、以及http协议自动REDIRECT到HTTPS【没有试验,内含设置强制https访问】
- WinInet Tutorial for Beginners and WinINet vs WinHTTP
- Apache虚拟目录配置及vue-cli反向代理的设置方法
- WinInet, WinHttp, Winsock, ws2_32的区别和联系
- iOS9中如何适配http,Bitcode,设置sina,qq,weChat配置Scheme白名单
- npm配置镜像、设置代理
- npm配置镜像、设置代理
- 一步一步教你学会抓包工具Charles的使用(下载破解+代理设置+证书配置)
- IIS中遇到无法预览的问题(HTTP 错误 401.3 - Unauthorized 由于 Web 服务器上此资源的访问控制列表(ACL)配置或加密设置,您无权查看此目录或页面。)
- [转]HttpWebRequest提高效率之连接数,代理,自动跳转,gzip请求等设置有关问题
- HTTP 代理设置