HttpReceiveHttpRequest и Windows XP SP2
функция HttpReceiveHttpRequest определяет правильно?
В Windows Server 2008 все хорошо.
DWORD DoReceiveRequests(
IN HANDLE hReqQueue
)
{
ULONG result;
HTTP_REQUEST_ID requestId;
DWORD bytesRead;
PHTTP_REQUEST pRequest;
PCHAR pRequestBuffer;
ULONG RequestBufferLength;
#define ANSWER 1024
char vv[2048] = "\0"; char k = 0;
//
// Allocate a 2 KB buffer. This size should work for most
// requests. The buffer size can be increased if required. Space
// is also required for an HTTP_REQUEST structure.
//
RequestBufferLength = sizeof(HTTP_REQUEST) + 2048;
pRequestBuffer = (PCHAR) ALLOC_MEM( RequestBufferLength );
memset(pRequestBuffer,0,RequestBufferLength);
if (pRequestBuffer == NULL)
{
return ERROR_NOT_ENOUGH_MEMORY;
}
pRequest = (PHTTP_REQUEST)pRequestBuffer;
//
// Wait for a new request. This is indicated by a NULL
// request ID.
//
HTTP_SET_NULL_ID( &requestId );
char Answer[ANSWER]="\0";
for(;;)
{
// RtlZeroMemory(pRequest, RequestBufferLength);
memset(pRequest,0,RequestBufferLength);
result = HttpReceiveHttpRequest(
hReqQueue, // Req Queue
requestId, // Req ID
HTTP_RECEIVE_REQUEST_FLAG_COPY_BODY, // Flags
pRequest, // HTTP request buffer
RequestBufferLength,// req buffer length
&bytesRead, // bytes received
NULL // LPOVERLAPPED
);
if(NO_ERROR == result)
{
//
// Worked!
//
switch(pRequest->Verb)
{
case HttpVerbGET:
{
//отправим ответ
result = SendHttpResponse(
hReqQueue,
pRequest,
200,
"OK",
""
);
break;
}
case HttpVerbPOST:
{
//посмотрим, что в содержимом request
if (pRequest->pEntityChunks)
{
if (Parsing((char*)pRequest->pEntityChunks[0].FromMemory.pBuffer,&in)>-1)
{
if (WorkWithData(in) == 0)
{
//отправим подтверждение
SendHttpResponse(
hReqQueue,
pRequest,
200,
"OK",
Answer
);
}
}
}
break;
}
default:
{
result = SendHttpResponse(
hReqQueue,
pRequest,
503,
"Not Implemented",
NULL
);
break;
}
}
if(result != NO_ERROR)
{
break;
}
//
// Reset the Request ID to handle the next request.
//
HTTP_SET_NULL_ID( &requestId );
}
else if(result == ERROR_MORE_DATA)
{
//
// The input buffer was too small to hold the request
// headers. Increase the buffer size and call the
// API again.
//
// When calling the API again, handle the request
// that failed by passing a RequestID.
//
// This RequestID is read from the old buffer.
//
requestId = pRequest->RequestId;
//
// Free the old buffer and allocate a new buffer.
//
RequestBufferLength = bytesRead;
FREE_MEM( pRequestBuffer );
pRequestBuffer = (PCHAR) ALLOC_MEM( RequestBufferLength );
if (pRequestBuffer == NULL)
{
result = ERROR_NOT_ENOUGH_MEMORY;
break;
}
pRequest = (PHTTP_REQUEST)pRequestBuffer;
}
else if(ERROR_CONNECTION_INVALID == result &&
!HTTP_IS_NULL_ID(&requestId))
{
// The TCP connection was corrupted by the peer when
// attempting to handle a request with more buffer.
// Continue to the next request.
HTTP_SET_NULL_ID( &requestId );
}
else
{
break;
}
}
if(pRequestBuffer)
{
FREE_MEM( pRequestBuffer );
}
return result;
}
ну, например потому, что в программе вы также плохо оформляете код как и на форуме, и у вас там ошибка закралась