Discussion:
HTTPOpenRequest fails with XP SP2
(too old to reply)
TL
2005-02-18 14:55:02 UTC
Permalink
Hi, I have a Program wiich works fine from Win2000Pro up to XP SP1.
Afte installing SP2 on my XP-Systems, the call to HTTPOpenRequest fails with
a Errorcode like (translated from german):
"A Databuffer given to a Systemcall is too small"

The Call is (in Delphi):
hRequest := HttpOpenRequest(hConnect, 'POST', URLC.lpszUrlPath, NIL, NIL,
@Accept, 0, 1);

Has anybody a Idea ?
Stephen Sulzer
2005-02-22 08:09:26 UTC
Permalink
What does your Accept variable declaration look like?

For the lplpszAcceptTypes parameter, HttpOpenRequest expects an array of
strings, with the array terminated by a NULL element. Even if you just want
to pass a single string--for example, '*/*', you must still provide it in an
array: the first array element being the '*/*' string, and the second array
element being a NULL string pointer.

Hope that helps.

- Stephen
Post by TL
Hi, I have a Program wiich works fine from Win2000Pro up to XP SP1.
Afte installing SP2 on my XP-Systems, the call to HTTPOpenRequest fails with
"A Databuffer given to a Systemcall is too small"
hRequest := HttpOpenRequest(hConnect, 'POST', URLC.lpszUrlPath, NIL, NIL,
@Accept, 0, 1);
Has anybody a Idea ?
TL
2005-02-22 10:57:03 UTC
Permalink
Hi Stephen,
thanks for your Hint, but I think this is ok.
Accept: Array[0..1] of PChar = (PChar('*/*'), NIL);
It works with XP SP1, only since SP2 I get the Error.
Windows Firewall is switched off. I've seen, that there is a new WinInet.DLL
installed with SP2.

I don't know whats to do. Is something changed with the Parameters ?
Stephen Sulzer
2005-02-24 09:54:36 UTC
Permalink
Your Accept variable looks Ok.

Just to confirm: the error code given by GetLastError after HttpOpenRequest
fails is 122 ? Error code 122 is ERROR_INSUFFICIENT_BUFFER.

How long is the lpszUrlPath string that is passed to HttpOpenRequest?
WinInet does not support URL path strings longer than 2048 characters (and
2083 characters max for the entire URL string). However, if your URL string
is too long, you should have encountered problems with WinInet before XP
SP2. I do not know what changes were made to HttpOpenRequest for XP SP2.

If the lpszUrlPath string is not very long (less than 2,000 characters),
then the next step would be to try the debug version of WinInet.dll and have
it generate a log file. The debug WinInet log file may contain information
about why the HttpOpenRequest API is failing. For information about
obtaining and using the debug WinInet.dll, see the following Microsoft
support article:

http://support.microsoft.com/?id=884931

The WinINET_Debug.exe package will contain different versions of
WinInet.dll. For XPSP2, use the DLL in the "XPSP2_customer_ready_2180"
folder.

Hope that helps.

Stephen
Post by TL
Hi Stephen,
thanks for your Hint, but I think this is ok.
Accept: Array[0..1] of PChar = (PChar('*/*'), NIL);
It works with XP SP1, only since SP2 I get the Error.
Windows Firewall is switched off. I've seen, that there is a new WinInet.DLL
installed with SP2.
I don't know whats to do. Is something changed with the Parameters ?
Murugan Andezuthu Dharmaratnam
2005-04-15 06:44:04 UTC
Permalink
Hi TL.
Try this sample code. Replace string tokenizer with L"Your Text:". Most
of the code is from MSDN. Check WinHttpQueryHeaders in MSDN .


// HTTPManager.cpp: implementation of the HTTPManager class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "HTTPManager.h"
#include "StringTokenizer.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

HTTPManager::HTTPManager()
{

}

HTTPManager::~HTTPManager()
{

}

bool HTTPManager::HTTPGetFileInfo(LPTSTR URL)
{

// ANSI TO Unicdoe


DWORD dwSize = 0;
LPVOID lpOutBuffer = NULL;
BOOL bResults = FALSE;
HINTERNET hSession = NULL,
hConnect = NULL,
hRequest = NULL;
DWORD dwDownloaded = 0;
LPSTR pszOutBuffer;



StringTokenizer* URLStringTokenizer = new StringTokenizer();
URLStringTokenizer->SetStringToken(URL,"/");
printf("%s",URLStringTokenizer->NextToken());

char szTemp[100] = "000000000000000000000000000000000000000000";
strcpy(szTemp ,URLStringTokenizer->NextToken("/"));
WCHAR wszTemp[100+1]; // Unicode ServerName
MultiByteToWideChar( CP_ACP, 0, szTemp ,
strlen(szTemp )+1, wszTemp,
100);
printf("\n%s",szTemp);




// Use WinHttpOpen to obtain a session handle.
hSession = WinHttpOpen( L"DA 7.0",
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS, 0 );


// Specify an HTTP server.
if( hSession )
hConnect = WinHttpConnect( hSession,wszTemp,
INTERNET_DEFAULT_PORT, 0 );


strcpy(szTemp ,URLStringTokenizer->NextToken(" "));
if(szTemp[strlen(szTemp)-2] == '\r')
szTemp[strlen(szTemp)-2] = '\0';
printf("\n%s",szTemp);

MultiByteToWideChar( CP_ACP, 0, szTemp ,
strlen(szTemp )+1, wszTemp,
100);

// Create an HTTP request handle.
if( hConnect )
hRequest = WinHttpOpenRequest( hConnect, L"GET", wszTemp,
NULL, WINHTTP_NO_REFERER,
0,
0);
// Add a request header.
if( hRequest )
bResults = WinHttpAddRequestHeaders( hRequest,
L"Range: bytes=0-",
-1,
WINHTTP_ADDREQ_FLAG_ADD );


// Send a request.
if( hRequest )
bResults = WinHttpSendRequest( hRequest,
WINHTTP_NO_ADDITIONAL_HEADERS, 0,
WINHTTP_NO_REQUEST_DATA, 0,
0, 0 );


// End the request.
if( bResults )
bResults = WinHttpReceiveResponse( hRequest, NULL );




/* New Added */


// First, use HttpQueryInfo to obtain the size of the buffer.
if (bResults)
{
WinHttpQueryHeaders( hRequest, WINHTTP_QUERY_RAW_HEADERS_CRLF,
WINHTTP_HEADER_NAME_BY_INDEX, NULL, &dwSize,
WINHTTP_NO_HEADER_INDEX);

// Allocate memory for the buffer.
if( GetLastError( ) == ERROR_INSUFFICIENT_BUFFER )
{
lpOutBuffer = new WCHAR[dwSize/sizeof(WCHAR)];

// Now, use HttpQueryInfo to retrieve the header.
bResults = WinHttpQueryHeaders( hRequest,
WINHTTP_QUERY_RAW_HEADERS_CRLF,
WINHTTP_HEADER_NAME_BY_INDEX,
lpOutBuffer, &dwSize,
WINHTTP_NO_HEADER_INDEX);
}
}

// Print the header contents.
if (bResults)
printf("Header contents: \n%S",lpOutBuffer);







/*End New Added - Delete Comment Final */



// Keep checking for data until there is nothing left.
if( bResults )
{
do
{
// Check for available data.
dwSize = 0;
if( !WinHttpQueryDataAvailable( hRequest, &dwSize ) )
printf( "Error %u in WinHttpQueryDataAvailable.\n",
GetLastError( ) );
printf("\n Number Of Bytes - %d \n",dwSize);
// Allocate space for the buffer.
pszOutBuffer = new char[dwSize+1];
if( !pszOutBuffer )
{
printf( "Out of memory\n" );
dwSize=0;
}
else
{
// Read the data.
ZeroMemory( pszOutBuffer, dwSize+1 );

if( !WinHttpReadData( hRequest, (LPVOID)pszOutBuffer,
dwSize, &dwDownloaded ) )
printf( "Error %u in WinHttpReadData.\n", GetLastError( ) );
else
printf( "%s", pszOutBuffer );

// Free the memory allocated to the buffer.
delete [] pszOutBuffer;
}
} while( dwSize > 0 );
}


// Report any errors.
if( !bResults )
printf( "Error %d has occurred.\n", GetLastError( ) );

// Close any open handles.
if( hRequest ) WinHttpCloseHandle( hRequest );
if( hConnect ) WinHttpCloseHandle( hConnect );
if( hSession ) WinHttpCloseHandle( hSession );


return false;
}


Hope this helps. If Needed I will write a sample projegram and send it to u.
I will post the StringTokenizer class in my web site on Apr 18 Monday (Need
to add few lines to comments :) ).


Thanks!
Murugan
www.muruganad.net

"Nothing is Impossible, Its just Improbable"
Post by TL
Hi, I have a Program wiich works fine from Win2000Pro up to XP SP1.
Afte installing SP2 on my XP-Systems, the call to HTTPOpenRequest fails with
"A Databuffer given to a Systemcall is too small"
hRequest := HttpOpenRequest(hConnect, 'POST', URLC.lpszUrlPath, NIL, NIL,
@Accept, 0, 1);
Has anybody a Idea ?
Loading...