Seshadri
2004-10-12 18:11:10 UTC
Dear All,
I have a problem with my code that refuses to work on a SSL which has
untrusted certificates, while trying to read a page. I think I have put in
the necessary flags for the code to ignore untrusted certificates, but still,
I get a null string every time. If I try the HTTP on the same server, it
works fine but HTTPS with an untrusted certificate, I get null string. I am
pasting the code below. If you could help me where I could be going wrong, it
will be great.
Thank you in advance.
- Sesahdri.
Code follows:
<<
CRegistrationDlg::CallInternet(void)
{
HINTERNET hSession =
InternetOpen("MembaGenesisInternetRequest",INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY,NULL,NULL,NULL);
HINTERNET hConnect =
InternetConnect(hSession,"pw-sesh-sdi",INTERNET_DEFAULT_HTTPS_PORT,"","",INTERNET_SERVICE_HTTP,0,0) ;
HINTERNET hHttpFile =
HttpOpenRequest(hConnect,"GET","/a.htm",HTTP_VERSION,NULL,0,INTERNET_FLAG_IGNORE_CERT_CN_INVALID
|INTERNET_FLAG_IGNORE_CERT_DATE_INVALID |INTERNET_FLAG_NO_COOKIES
|INTERNET_FLAG_RELOAD |INTERNET_FLAG_SECURE |INTERNET_FLAG_DONT_CACHE,0);
BOOL bSendRequest = HttpSendRequest(hHttpFile, NULL, 0, 0, 0);
char bufQuery[32] ;
DWORD dwLengthBufQuery = sizeof(bufQuery);
BOOL bQuery =
HttpQueryInfo(hHttpFile,HTTP_QUERY_CONTENT_LENGTH,bufQuery,&dwLengthBufQuery,0) ;
DWORD dwFileSize = (DWORD)atol(bufQuery) ;
char* buffer = new char[dwFileSize+1] ;
DWORD dwBytesRead ;
BOOL bRead = InternetReadFile(hHttpFile,buffer,dwFileSize+1,
&dwBytesRead);
buffer[dwBytesRead] = 0 ;
InternetCloseHandle(hHttpFile);
InternetCloseHandle(hConnect) ;
InternetCloseHandle(hSession) ;
AfxMessageBox(buffer);
}
I have a problem with my code that refuses to work on a SSL which has
untrusted certificates, while trying to read a page. I think I have put in
the necessary flags for the code to ignore untrusted certificates, but still,
I get a null string every time. If I try the HTTP on the same server, it
works fine but HTTPS with an untrusted certificate, I get null string. I am
pasting the code below. If you could help me where I could be going wrong, it
will be great.
Thank you in advance.
- Sesahdri.
Code follows:
<<
CRegistrationDlg::CallInternet(void)
{
HINTERNET hSession =
InternetOpen("MembaGenesisInternetRequest",INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY,NULL,NULL,NULL);
HINTERNET hConnect =
InternetConnect(hSession,"pw-sesh-sdi",INTERNET_DEFAULT_HTTPS_PORT,"","",INTERNET_SERVICE_HTTP,0,0) ;
HINTERNET hHttpFile =
HttpOpenRequest(hConnect,"GET","/a.htm",HTTP_VERSION,NULL,0,INTERNET_FLAG_IGNORE_CERT_CN_INVALID
|INTERNET_FLAG_IGNORE_CERT_DATE_INVALID |INTERNET_FLAG_NO_COOKIES
|INTERNET_FLAG_RELOAD |INTERNET_FLAG_SECURE |INTERNET_FLAG_DONT_CACHE,0);
BOOL bSendRequest = HttpSendRequest(hHttpFile, NULL, 0, 0, 0);
char bufQuery[32] ;
DWORD dwLengthBufQuery = sizeof(bufQuery);
BOOL bQuery =
HttpQueryInfo(hHttpFile,HTTP_QUERY_CONTENT_LENGTH,bufQuery,&dwLengthBufQuery,0) ;
DWORD dwFileSize = (DWORD)atol(bufQuery) ;
char* buffer = new char[dwFileSize+1] ;
DWORD dwBytesRead ;
BOOL bRead = InternetReadFile(hHttpFile,buffer,dwFileSize+1,
&dwBytesRead);
buffer[dwBytesRead] = 0 ;
InternetCloseHandle(hHttpFile);
InternetCloseHandle(hConnect) ;
InternetCloseHandle(hSession) ;
AfxMessageBox(buffer);
}