What can call ERROR_INTERNET_INCORRECT_HANDLE_TYPE (12018) with InternetQueryOption?

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, ...)
+3
source share
4 answers

In the MSDN docs for INTERNET_OPTION_SECURITY_FLAGS:

Keep in mind that data refers to a transaction that has occurred, the security level of which cannot last longer.

. InternetOpen HINTERNET. HTTP, FTP Gopher, HTTPS , . , Wininet , .

+1

, hReq, InternetOpen. , . , , InternetOpen:

if (hReq == NULL) {
    printf("InternetOpen Error: %d", GetLastError());
}
0

, () . , "sample":

  HINTERNET hReq = InternetOpen(...)
  if (!hReq) { printf("InternetOpen Error: %d", GetLastError()); }

  DWORD dwFlags = 0;
  DWORD dwBuffLen = sizeof(dwFlags);
  BOOL ret = false;

  InternetQueryOption(hReq, INTERNET_OPTION_SECURITY_FLAGS,
                      (LPVOID)&dwFlags, &dwBuffLen);
  if (!ret) { printf("InternetGetOption 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, ...)

, HINTERNET (hReq) InternetOpenURL - SSL (.. HTTP), , -, , . InternetQueryOption ?

0
source

I was getting a similar error. Then I passed the handle returned by HttpOpenRequest (...) to InternetQueryOption, and it worked fine. Give it a try.

0
source

Source: https://habr.com/ru/post/1699383/


All Articles