Click to See Complete Forum and Search --> : Downloading file using http


Lim Dau Hee
April 12th, 1999, 01:35 AM
I wrote the code below to download a zip file from a web site using http. However when I try it out, it seems that the zip file would be slightly larger than the original file by a few hundred bytes. What am I doing wrong? I kinda suspect that it is due to fwrite(). Or could anyone suggest a better method? Thanks.

int iNumberOfBytesRead;
void *vBytesReadFromFile;
CInternetSession internetSession;
CHttpFile* httpFile = (CHttpFile*)internetSession.OpenURL(url);

vBytesReadFromFile = malloc(sizeof(char) * 4096);

while (1)
{
iNumberOfBytesRead = httpFile->Read(vBytesReadFromFile, 4096);
fwrite(vBytesReadFromFile, iNumberOfBytesRead, 1, fOutput);
if (iNumberOfBytesRead != 4096)
break;
}

httpFile->Close();
fclose(fOutput);

STT
May 21st, 1999, 04:32 AM
I've made it with a CFile and CFile::Write instead of fwrite and i do not have the problem you described.

There is another little bug with html files when the connexion is very slow : sometimes, the files are incomplete ( i do not see that with zip files or images...)