Link to home
Start Free TrialLog in
Avatar of davidmorand
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.OpenURL( "http://netdev1/~foo/bar/bar.ini"));

pHttpFile->SendRequest("", NULL, 0);

DWORD dwStatus;
pHttpFile->QueryInfoStatusCod(dwStatus);            

if (dwStatus < 200 || dwStatus > 299)
      AfxThrowInternetException(pConnection->GetContext());

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!
Avatar of davidmorand
davidmorand

ASKER

BTW, the size returned seems to be pretty random but around 700 bytes...
ASKER CERTIFIED SOLUTION
Avatar of mikeblas
mikeblas

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial