I am working on a simple little function to download a file from an SSL-enabled website using WinInet features, namely InternetOpen and InternetOpenURL. At first I was not able to call InternetOpenURL using ERROR_INTERNET_INVALID_CA(12045), because I used a self-signed certificate on my test server and found ( http://support.microsoft.com/kb/q182888/ ) that the fix seemed to be using a combination of InternetQueryOption / InternetSetOption to pass various flags to the parameter INTERNET_OPTION_SECURITY_FLAGS. Now, however, InternetQueryOption does not work with the answerERROR_INTERNET_INCORRECT_HANDLE(12018) from GetLastError (). Any ideas why this would be so? I use a descriptor that comes directly from InternetOpen, which previously worked perfectly with the non-SSL InternetOpenURL server. Shouldn't that be the right pen?
I do not have the actual code (on another computer), but it is very similar to the following and does not work in InternetGetOption with ERROR_INTERNET_INCORRECT_HANDLE:
HINTERNET hReq = InternetOpen(...)
if (!hReq) { printf("InternetOpen Error: %d", GetLastError()); }
DWORD dwFlags = 0;
DWORD dwBuffLen = sizeof(dwFlags);
BOOL ret = false;
ret = InternetQueryOption(hReq, INTERNET_OPTION_SECURITY_FLAGS,
(LPVOID)&dwFlags, &dwBuffLen);
if (!ret) { printf("InternetQueryOption Error: %d", GetLastError()); }
dwFlags |= SECURITY_FLAG_IGNORE_UNKNOWN_CA;
ret = InternetSetOption(hReq, INTERNET_OPTION_SECURITY_FLAGS,
&dwFlags, sizeof (dwFlags) );
if (!ret) { printf("InternetSetOption Error: %d", GetLastError()); }
InternetOpenURL(hReq, ...)
Daffodil soda
source
share