Home > Software engineering >  HttpQueryInfo, error 12150 without the content length
HttpQueryInfo, error 12150 without the content length

Time:09-28

Extern "C" __declspec (dllexport) string GetHTML (char * URL)
{
HINTERNET Session=InternetOpenA (NULL, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, NULL);
If (NULL==Session)
{
InternetCloseHandle (Session);
return "";
}
DWORD d=GetLastError ();
URL="http://www.baidu.com";
HINTERNET hHttpFile=InternetOpenUrlA (Session, URL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, NULL);

If (NULL==hHttpFile)
{
InternetCloseHandle (hHttpFile);
InternetCloseHandle (Session);

CHAR szError [256].
DWORD dwErrorSize=256;
DWORD dwLastErrorMsg;
InternetGetLastResponseInfo (& amp; DwLastErrorMsg, LPWSTR szError, & amp; DwErrorSize);
String m_strTmperror=szError;

D=GetLastError ();
return "";
}
D=GetLastError ();
Char szSizeBuffer [32].
DWORD dwLengthSizeBuffer=sizeof (szSizeBuffer);
DWORD dwFileSize=10 * 1024;
If (: : HttpQueryInfo (hHttpFile, HTTP_QUERY_CONTENT_LENGTH szSizeBuffer, & amp; DwLengthSizeBuffer, NULL)==TRUE)
{
//allocating the memory space for HTTP file contents
DwFileSize=atol (szSizeBuffer);
}
The else
D=GetLastError ();//always here 12150 because can't get content length, always don't play full read data, not much is less, why didn't find the data length?

PBYTE pbufs=new BYTE [dwFileSize * sizeof (TCHAR)];
If (NULL==pbufs)
{

InternetCloseHandle (hHttpFile);
InternetCloseHandle (Session);
return FALSE;
}
DWORD dwReadDataLength=NULL;
BOOL bRet=TRUE;
Do
{
//ZeroMemory (pbufs, dwMaxDataLength * sizeof (TCHAR));
BRet=InternetReadFile (hHttpFile, pbufs dwFileSize, & amp; DwReadDataLength);

} while (NULL!=dwReadDataLength);
Pbufs return (char *);
}
  • Related