Any help???
What type of server is it?
Did you check the status code?
Paul
"Omer B." <om...@commtouch.com> wrote in message
news:135d32fd.04120...@posting.google.com...
I didnt check the status code, I checked the return value of each
WinInet API and all indicated success. However, the buffer that
received the data from InternetReadFile API contained "<h1>Bad
Request</h1>".
What am I missing?
Paul
"omerb" <om...@commtouch.com> wrote in message
news:1102347162.5...@z14g2000cwz.googlegroups.com...
Here is the code I use (removed the HttpQueryInfo calls):
CONST TCHAR *szAcceptType = "*/*";
HINTERNET hSession = InternetOpen("MyAgent",
INTERNET_OPEN_TYPE_PRECONFIG, "localhost", NULL, 0);
if(hSession == NULL)
{
cout << "error in InternetOpen: " << GetLastError() << endl;
return;
}
HINTERNET hConnect = InternetConnect(hSession, _T(sServerName.c_str()),
INTERNET_DEFAULT_HTTPS_PORT ,
NULL,
NULL, INTERNET_SERVICE_HTTP, 0, 1);
if(hConnect == NULL)
{
cout << "error in InternetConnect: " << GetLastError() << endl;
return;
}
HINTERNET hRequest = HttpOpenRequest(hConnect, "GET",
_T(strObject.c_str()),
HTTP_VERSION, "", &szAcceptType,
INTERNET_FLAG_SECURE |
INTERNET_FLAG_IGNORE_CERT_CN_INVALID |
INTERNET_FLAG_IGNORE_CERT_DATE_INVALID |
INTERNET_FLAG_NO_CACHE_WRITE, 1);
if(hRequest == NULL)
{
cout << "error in HttpOpenRequest" << endl;
return;
}
if(!HttpSendRequest(hRequest, NULL, 0, NULL, 0))
{
cout << "error in HttpSendRequest: " << GetLastError() << endl;
return;
}
DWORD dwSize;
if (!InternetQueryDataAvailable(hRequest,&dwSize,0,0))
{
cout << "Error Occured in calling InternetQueryDataAvailable"
<< endl;
return;
}
DWORD dwDownloaded;
char szBuff[1024] = {0};
if(InternetReadFile(hRequest,(LPVOID)szBuff,1023,&dwDownloaded))
{
while(dwDownloaded > 0)
{
cout << szBuff;
if(!InternetReadFile(hRequest,(LPVOID)szBuff,1023,&dwDownloaded))
{
cout << "error" << endl;
return;
}
}
}
So your szAcceptType variable declaration should look like this instead:
const TCHAR * szAcceptType[] = { _T("*/*"), NULL };
And change your call to HttpOpenRequest to pass szAcceptType accordingly (no
need for the extra dereference):
HINTERNET hRequest = HttpOpenRequest(hConnect, "GET",
_T(strObject.c_str()),
HTTP_VERSION, "", szAcceptType,
INTERNET_FLAG_SECURE |
INTERNET_FLAG_IGNORE_CERT_CN_INVALID |
INTERNET_FLAG_IGNORE_CERT_DATE_INVALID |
INTERNET_FLAG_NO_CACHE_WRITE, 1);
Hope that helps.
Stephen