我正在尝试用C ++从Internet下载文件。将下载的内容保存到HInternet实例中。
我也填充了HInternet实例的头信息。这看起来像是
Header contents:
HTTP/1.1 200 OK
Cache-Control: no-cache
Date: Fri, 24 Nov 2017 07:00:26 GMT
Pragma: no-cache
Content-Length: 71156
Content-Type: text/html
Expires: -1
Server: Microsoft-IIS/8.0
Content-Disposition: attachment; filename=642078_3855u.zip
X-AspNet-Version: 4.0.30319
Error 0 has occurred.
现在我正在尝试将642088_3855u.zip文件复制到某个位置。
所以,我试过,
if (bResults)
{
do
{
// Check for available data.
dwSize = 0;
if (!WinHttpQueryDataAvailable(hRequest, &dwSize))
{
dwLastError = GetLastError();
break;
}
// No more available data.
if (!dwSize)
break;
// Allocate space for the buffer.
pszOutBuffer = new char[dwSize + 1];
if (!pszOutBuffer)
{
bError = true;
break;
}
FILE *pfDestination = NULL;
_wfopen_s(&pfDestination, strDestinationFolder + L"\\" + L"642078_3855u.zip", L"w+b");
if (pfDestination == NULL)
{
bError = true;
break;
}
// Read the Data.
ZeroMemory(pszOutBuffer, dwSize + 1);
if (WinHttpReadData(hRequest, (LPVOID)pszOutBuffer,
dwSize, &dwDownloaded))
{
fwrite(pszOutBuffer, 1, dwDownloaded, pfDestination);
}
// Free the memory allocated to the buffer.
delete[] pszOutBuffer;
fclose(pfDestination);
// reported that there are bits to read.
if (!dwDownloaded)
break;
} while (dwSize > 0);
}
我没有收到任何错误,zip的实际大小如果是72kb但它是用4kb创建的zip文件,当我试图打开zip文件时,我收到错误无效的zip文件。
请注意:zip文件也包含可执行文件。
我犯错误的任何建议。
谢谢,