CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 1999
    Posts
    5

    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);


  2. #2
    Join Date
    May 1999
    Location
    Paris, France
    Posts
    11

    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...)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured