如何使用 WinInet 进行 SSL 请求
How To Make SSL Requests Using WinInet
It is possible to establish a Secure Socket Layer (SSL) or Private Communications Technology (PCT) HTTP session with the WinInet APIs. Secure HTTP, denoted as HTTPS://, takes place over TCP port 443. Code similar to the following can be used to establish an HTTPS session:
... hOpen = InternetOpen (...); Connect = InternetConnect ( hOpen, // InternetOpen handle "MyHttpServer", // Server name INTERNET_DEFAULT_HTTPS_PORT,// Default HTTPS port - 443 "", // User name "", // User password INTERNET_SERVICE_HTTP, // Service 0, // Flags 0 // Context ); hReq = HttpOpenRequest ( hConnect, // InternetConnect handle "GET", // Method "", // Object name HTTP_VERSION, // Version "", // Referrer NULL, // Extra headers INTERNET_FLAG_SECURE, // Flags 0 // Context ); ...
Please note two differences when using HTTPS instead of HTTP:
- InternetConnect uses INTERNET_DEFAULT_HTTPS_PORT instead of INTERNET_INVALID_PORT_NUMBER or INTERNET_DEFAULT_HTTP_PORT
- HttpOpenRequest uses the INTERNET_FLAG_SECURE option in addition to all other options.
The following two options can be used either in HttpOpenRequest or in InternetOpenUrl to ignore invalid certificate errors:
- INTERNET_FLAG_IGNORE_CERT_CN_INVALID - Ignores errors that can be caused by the certificate host name of the server not matching the host name in the request.
- INTERNET_FLAG_IGNORE_CERT_DATE_INVALID - Ignores errors that can be caused by an expired server certificate.
Please see the Internet Client SDK documentation for more information on these flags.
SSL and PCT functionality are provided by Schannel.dll, which is properly installed when you run the redistribution program Wintdist.exe or Wint351.exe. See Redist.txt or Axredist.txt for information about redistributing Schannel.dll.
转自: http://support.microsoft.com/default.aspx?scid=kb;en-us;168151
翻译这段:
Please note two differences when using HTTPS instead of HTTP:
- InternetConnect uses INTERNET_DEFAULT_HTTPS_PORT instead of INTERNET_INVALID_PORT_NUMBER or INTERNET_DEFAULT_HTTP_PORT
- HttpOpenRequest uses the INTERNET_FLAG_SECURE option in addition to all other options.
翻译如下:
请注意两个差异在使用HTTPS而不是HTTP:
InternetConnect使用 INTERNET_DEFAULT_HTTPS_PORT 而不是 INTERNET_INVALID_PORT_NUMBER 或 INTERNET_DEFAULT_HTTP_PORT
HttpOpenRequest使用互联网旗安全选项除了所有其他选项。//这段翻译不到,英文差。我用翻译软件的。还没有测试过。-_-!