我有这段代码:
int Request(char* Method, LPCSTR Host, LPCSTR url, LPCSTR header, LPSTR data, bool ssl){
//http://msdn.microsoft.com/en-us/library/windows/desktop/aa385096%28v=vs.85%29.aspx
HINTERNET internet = InternetOpenA("Firefox", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (internet != NULL)
{
//http://msdn.microsoft.com/en-us/library/windows/desktop/aa384363%28v=vs.85%29.aspx
HINTERNET connect = InternetConnectA(internet, Host, port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
if (connect != NULL)
{
//Here I want to get the certificate from the server and check the thumbprint. If it's not the want I want I don't do any request
if(thumbprint != "49023842938429034809234"){
InternetCloseHandle(connect);
InternetCloseHandle(internet);
return error;
}
//http://msdn.microsoft.com/en-us/library/windows/desktop/aa384233%28v=vs.85%29.aspx
HINTERNET request = HttpOpenRequestA(connect, m, url, "HTTP/1.1", NULL, NULL,
dwFlags, NULL);
if (request != NULL)
{
int datalen = 0;
if (data != NULL) datalen = strlen(data);
int headerlen = 0;
if (header != NULL) headerlen = strlen(header);
//http://msdn.microsoft.com/en-us/library/windows/desktop/aa384247%28v=vs.85%29.aspx
HttpSendRequestA(request, header, headerlen, data, datalen);
//http://msdn.microsoft.com/en-us/library/windows/desktop/aa384350%28v=vs.85%29.aspx
InternetCloseHandle(request);
}
}
InternetCloseHandle(connect);
}
InternetCloseHandle(internet);
}
我想查看指纹,如果服务器没有提供预期的指纹,我将关闭连接并且不启动实际请求。
我看过这篇文章,但是作者做了一个HEAD请求来获取它。 http://blogs.msdn.com/b/jpsanders/archive/2009/04/17/how-to-get-certificate-information-using-wininet-apis.aspx。在连接到服务器后,我无法获得证书详细信息吗?
谢谢