Downloading file using http
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);
Re: Downloading file using http
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...)