简体   繁体   中英

Using SSL with Wininet

Someone can give me example how to use SSL with wininet API's ? Here is my code but no success.....

DWORD dwFlags = INTERNET_FLAG_SECURE|INTERNET_FLAG_IGNORE_CERT_CN_INVALID|SECURITY_FLAG_IGNORE_UNKNOWN_CA|INTERNET_FLAG_IGNORE_CERT_DATE_INVALID|INTERNET_FLAG_NO_AUTO_REDIRECT|INTERNET_FLAG_PRAGMA_NOCACHE|INTERNET_FLAG_NO_CACHE_WRITE;

hOpen = InternetOpen(UserAgent,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
hConnect = InternetConnect(hOpen,Url,INTERNET_DEFAULT_HTTPS_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
hRequest = HttpOpenRequest(hConnect,GET,Pages,NULL,NULL,NULL,dwFlags,0);

HttpSendRequest(hRequest,ContentType,-1L,NULL,0);

Thanks in advance.

For sites that use valid certificates, you shouldn't have to do anything special, other than specifying the https URL, of course. For self-generated certificates you may need to manually install the certificate authority on the client machine, and/or provide some of the IGNORE flags.

A great way to troubleshoot issues like this is to install a WININET callback. This lets you monitor the progress that WININET is making (or not) while communicating.

There's an example (that I haven't personally used) of how to use it here:

http://www.codeproject.com/Articles/25185/WinINet-Test-Application

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM