HttpReceiveRequestEntityBody 使用应注意的地方
如果EntityBody数据很大,调用此函数是不能完全接收全部数据的,我们不能简单的判断
BYTE* pBuffer = new BYTE[4096]; ZeroMemory(pBuffer, 4096); string entityData; DWORD dwReceived = 0; if((NO_ERROR == HttpReceiveRequestEntityBody(reqQueueHandle, requestId, 0, pBuffer, 4096, &dwReceived, NULL)) && dwReceived > 0) { entityData += pBuffer; } delete[] pBuffer;
就认为已经接受了全部的数据,根据PlatformSDK的注释:
Remarks
To retrieve an entire entity body, an application is expected to call HttpReceiveRequestEntityBody, passing in new buffers, until the function returns ERROR_HANDLE_EOF. As long as a buffer full of entity-body data is copied successfully and there is still more entity-body data waiting to be retrieved, the function returns NO_ERROR.
我们应该这样做
BYTE* pBuffer = new BYTE[4096]; ZeroMemory(pBuffer, 4096); string entityData; DWORD dwReceived = 0; while((ERROR_HANDLE_EOF != HttpReceiveRequestEntityBody(reqQueueHandle, requestId, 0, pBuffer, 4096, &dwReceived, NULL)) && (dwReceived > 0)) { entityData += pBuffer; ZeroMemory(pBuffer, 4096); } delete[] pBuffer;