HttpReceiveRequestEntityBody

HttpReceiveRequestEntityBody

如果EntityBody数据很大,调用此函数是不能完全接收全部数据的,我们不能简单的判断

   1: BYTE* pBuffer = new BYTE[4096];
   2: ZeroMemory(pBuffer, 4096);
   3: string entityData;
   4: DWORD dwReceived = 0;
   5: if((NO_ERROR == HttpReceiveRequestEntityBody(reqQueueHandle, requestId, 0, pBuffer, 4096, &dwReceived, NULL)) && dwReceived > 0) {
   6:     entityData += pBuffer;
   7: }
   8: 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.

我们应该这样做

   1: BYTE* pBuffer = new BYTE[4096];
   2: ZeroMemory(pBuffer, 4096);
   3: string entityData;
   4: DWORD dwReceived = 0;
   5: while((ERROR_HANDLE_EOF != HttpReceiveRequestEntityBody(reqQueueHandle, requestId, 0, pBuffer, 4096, &dwReceived, NULL)) && (dwReceived > 0)) {
   6:     entityData += pBuffer;
   7:     ZeroMemory(pBuffer, 4096);
   8: }
   9: delete[] pBuffer;

04-16 13:17