WinHTTP is Microsoft Windows HTTP Services. It provides developers with an HTTP client application.ProgramAn API that uses the HTTP protocol to send requests to other HTTP servers.
WinHTTP supports desktop applications, Windows Services, and Windows Server applications.
For Microsoft. NET Framework-based applications, the WinHTTP service is not recommended because. NET Framework applications should use the network infrastructure type in the system. Net namespace.
WinHTTP provides two programming methods: C \ c ++ APIs and COM components.
Differences between WinHTTP and wininet
======================
WinHTTP is designed to be mainly used in server-side applications to allow server-side applications to access the HTTP server.
Wininet is an older technology designed as an HTTP client platform for interactive desktop applications, such as IE and office.
Server applications require the HTTP client service to use WinHTTP instead of wininet.
WinHTTP and wininet are supported by different teams at Microsoft.
WinHTTP and proxy
======================
If the HTTP proxy requires authentication, the HTTP application will receive the 407 (proxy requires authentication ). in addition to this status code, the proxy server also sends one or more authenticate headers: "proxy-authenticate ". this information is sufficient for us to identify in the network monitor trace whether HTTP cannot be accessed because the proxy needs authentication.
The proxy configuration of WinHTTP is stored in the registry key.
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\Winhttpsettings
In, modify and view to use a command line tool proxycfg.
In fact, there are two methods to access HTTP and HTTPS hosts through a proxy.
- Specify the proxy configuration in the application. Example:
Hsession = winhttpopen (L& Quot; WinHTTP example/1.0 & quot", Winhttp_access_type_named_proxy, l"Proxy_name", L"<Local>", 0 );
Or
Winhttp_proxy_info proxyinfo; proxyinfo. dwaccesstype = winhttp_access_type_named_proxy; proxyinfo. lpszproxy = L"Proxy_name"; Proxyinfo. lpszproxybypass = L"<Local>";// Set the proxy information for this session.Winhttpsetoption (hsession, winhttp_option_proxy, & proxyinfo,Sizeof(Proxyinfo ));
Configure the default proxy configuration outside the application. Use the command line tool proxycmd.exe located in the directory % WinDir % \ System32.
Proxycfg-P "HTTP = http_proxy HTTPS = https_proxy" "<local>; * .microsoft.com"
The above command specifies to use the proxy server named http_proxy to access the HTTP host, and use the proxy server named https_proxy to access the HTTPS host.
This command also specifies that no proxy is used to access any site that matches "* .microsoft.com" on the Local intranet.
Differences between classes in WinHTTP and system. Net in proxy configuration
====================
As mentioned above, if the application is Based on. NET Framework, we do not recommend using WinHTTP as the HTTP client. We recommend that you use the following type. WinHTTP in system. net.CodeOr proxycfg to configure. What is the configuration of the type under system. Net?
The answer is that the config file.. NET Framework uses the standard XML file as the configuration file to store configuration information. The executable file is the. config file, and the Asp.net site has the web. config file.
<System.. Net> the element contains the specified.. NET Framework. the <defaultproxy> element contains the configuration of the HTTP proxy server. this element has three child elements:
- Bypasslist-providesRegular ExpressionIs used to describe sites that do not apply to proxies.
- Module-Add a new proxy module for the Application
- Proxy-specify the Proxy Server
Example
< Configuration > < System.net > < Defaultproxy > < Bypasslist > < Add Address = " [A-Z] + \. contoso \. com $ "/> < Add Address = " 192 \. 168 \. \ D {} \. \ D} " /> </ Bypasslist > </ Defaultproxy > </ System.net > </ Configuration >
References:
Windows HTTP Services
Http://msdn.microsoft.com/en-us/library/aa384273%28v=VS.85%29.aspx
Proxycfg on win2003 and netsh on win2008
Http://www.cnblogs.com/awpatp/archive/2010/05/13/1734762.html
Using the WinHTTP proxy configuration Utility
Http://msdn.microsoft.com/en-us/library/ms761351%28VS.85%29.aspx
Proxycmd.exe, a proxy configuration tool
Http://msdn.microsoft.com/en-us/library/aa384069%28v=VS.85%29.aspx
<Bypasslist> element (network settings)
Http://msdn.microsoft.com/en-us/library/31465c77.aspx