我是参考这篇**改写的
https://www.cnblogs.com/jkcx/p/6374026.html
// 我把下面的代码修改了一下,WinHttpReadData读入的数据为啥返回的长度一直是0
DWORD BUF_LEN = 1024, ReadedLen = 0;
BYTE *pBuffer = NULL;
pBuffer = new BYTE[BUF_LEN];
HANDLE hFile = CreateFileW(FileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
while (int(dwContentSize) >=0 ) // dwContentSize转换成正数
{
ZeroMemory(pBuffer, BUF_LEN);
WinHttpReadData(hRequest, pBuffer, BUF_LEN, &dwReadBytes);
ReadedLen += dwReadBytes;
printf("debugging.\n");
printf("%d\n",dwReadBytes); // 这里的dwReadBytes始终返回是0,是什么原因?
// 写入文件
WriteFile(hFile, pBuffer, dwReadBytes, &dwReadBytes, NULL);
dwContentSize -= ReadedLen;
}
|