See the question and my original answer on StackOverflow

Wininet has a bunch of extended functions, options and structures that are not documented as such in MSDN but are only available with a winineti.h (note the ending 'i') header file that should be present aside the standard wininet.h file. You don't need any external lib, they are implemented by wininet.dll (and available for linking in wininet.lib).

You will be interested specifically by the INTERNET_OPTION_SECURITY_CONNECTION_INFO option that should get you exactly what you need.

You have to pass a pointer to an INTERNET_SECURITY_CONNECTION_INFO struct. This struct contains a connectionInfo field of type SecPkgContext_ConnectionInfo which is fully documented. This struct is in fact defined by SSPI/Schannel which is what Wininet uses internally to handle all low level protocol work.

Here is a sample code that you can add to your existing code:

INTERNET_SECURITY_CONNECTION_INFO connInfo = { 0 };
DWORD certInfoLength = sizeof(INTERNET_SECURITY_CONNECTION_INFO);
InternetQueryOption(hHttpRequest, INTERNET_OPTION_SECURITY_CONNECTION_INFO, &connInfo, &certInfoLength);

// now, connInfo.connectionInfo should contain all you need