在http服务器下载文件
CInternetSession isSession;
//CString strDownloadURL = GetURLOfConfig();
CString strDownloadURL = _T("http://192.168.18.140/temp/VersionInfo.txt");
CHttpFile *pHttpFile = (CHttpFile *)isSession.OpenURL(strDownloadURL);
ULONGLONG ullLen = pHttpFile->GetLength();
BYTE *pBuf = new BYTE[ullLen];
if (!pBuf)
{
return false;
}
DWORD dwWriten;
pHttpFile->Read(pBuf, ullLen);
//当把test.zip改成test.txt完全OK, 但是test.zip就不行,test.zip文件打不开
HANDLE hFile = ::CreateFile(_T("test.zip"), GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
return false;
}
DWORD dwError = GetLastError();
::WriteFile(hFile, pBuf, ullLen, &dwWriten, NULL);
CloseHandle(hFile);
isSession.Close();
pHttpFile->Close();