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;

转载于:https://www.cnblogs.com/mforestlaw/p/3289389.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值