davidmorand
asked on
Problems with CHttpFiles
I need to download a file from a server and my problem is that the size of the file is wrong. Here's my code:
pHttpFile = (CHttpFile*)(session.OpenU RL( "http://netdev1/~foo/bar/bar.ini"));
pHttpFile->SendRequest("", NULL, 0);
DWORD dwStatus;
pHttpFile->QueryInfoStatus Cod(dwStat us);
if (dwStatus < 200 || dwStatus > 299)
AfxThrowInternetException( pConnectio n->GetCont ext());
CString csFilename = APPINFO->GetAppRootPath() + "bar.ini";
CFile fileLocal(csFilename,
CFile::modeCreate | CFile::modeWrite);
int iLen = pHttpFile->GetLength();
BYTE* pBuf = new BYTE[iLen];
pHttpFile->Read(pBuf, iLen);
fileLocal.Write(pBuf, iLen);
fileLocal.Close();
pHttpFile->Close();
The problem is that the GetLenght method does not return the right size but the file is all here because if I change the value of iLen before it is used and set it to the right size everything is fine!
pHttpFile = (CHttpFile*)(session.OpenU
pHttpFile->SendRequest("",
DWORD dwStatus;
pHttpFile->QueryInfoStatus
if (dwStatus < 200 || dwStatus > 299)
AfxThrowInternetException(
CString csFilename = APPINFO->GetAppRootPath() + "bar.ini";
CFile fileLocal(csFilename,
CFile::modeCreate | CFile::modeWrite);
int iLen = pHttpFile->GetLength();
BYTE* pBuf = new BYTE[iLen];
pHttpFile->Read(pBuf, iLen);
fileLocal.Write(pBuf, iLen);
fileLocal.Close();
pHttpFile->Close();
The problem is that the GetLenght method does not return the right size but the file is all here because if I change the value of iLen before it is used and set it to the right size everything is fine!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER