how to Ignore certificate in HttpPOST request in WINAPI

后端 未结 1 860
温柔的废话
温柔的废话 2021-01-16 16:52

I have a VC++ HttpPOST method which works fine for both 80 and 443 port. (on popular websites like google.com)

Now when I connect to a secured host(172.17.9.93) havi

1条回答
  •  醉梦人生
    2021-01-16 17:22

    HttpOpenRequest work only with flags form INTERNET_FLAG_* - pass flag SECURITY_FLAG_IGNORE_UNKNOWN_CA to HttpOpenRequest this is error.

    look for numeric values:

    #define SECURITY_FLAG_IGNORE_UNKNOWN_CA         0x00000100
    
    #define INTERNET_FLAG_PRAGMA_NOCACHE    0x00000100  // asking wininet to add "pragma: no-cache"
    

    so if you try pass SECURITY_FLAG_IGNORE_UNKNOWN_CA to HttpOpenRequest you really pass INTERNET_FLAG_PRAGMA_NOCACHE flag

    SECURITY_FLAG_IGNORE_UNKNOWN_CA is designed to use in InternetSetOption function with INTERNET_OPTION_SECURITY_FLAGS

    so you need this code use:

    DWORD dwFlags;
    DWORD dwBuffLen = sizeof(dwFlags);
    
    if (InternetQueryOption (hRequest, INTERNET_OPTION_SECURITY_FLAGS, &dwFlags, &dwBuffLen))
    {
        dwFlags |= SECURITY_FLAG_IGNORE_UNKNOWN_CA;
        InternetSetOption (hRequest, INTERNET_OPTION_SECURITY_FLAGS, &dwFlags, sizeof (dwFlags));
    }
    

    also read How To Handle Invalid Certificate Authority Error with WinInet - Method 2. Without a UI: is exactly your case

    0 讨论(0)
提交回复
热议问题