How to download a binary file via http ? - Programmer

This is a discussion on How to download a binary file via http ? - Programmer ; Hi, I am using MS VC++ 6.0, and I am using the CHttpConnection and CHttpFile to download files from a web server. Everything is working fine for ascii files. When I download a binary file I get a corrupted file, ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: How to download a binary file via http ?

  1. How to download a binary file via http ?

    Hi,

    I am using MS VC++ 6.0, and I am using the CHttpConnection and
    CHttpFile to download files from a web server. Everything is working
    fine for ascii files.

    When I download a binary file I get a corrupted file, however.

    I tried adding the INTERNET_FLAG_BINARY_TRANSFER flag, so that
    might calls look like this:

    CHttpFile* pFile = NULL;
    if ( this->m_binary_transfer != 0)
    {
    pFile = pConnect->OpenRequest(CHttpConnection::HTTP_VERB_GET,
    url_str, NULL, 1,
    NULL, NULL,
    INTERNET_FLAG_EXISTING_CONNECT|INTERNET_FLAG_TRANS FER_BINARY );
    }
    else
    {
    pFile = pConnect->OpenRequest(CHttpConnection::HTTP_VERB_GET,
    url_str, NULL, 1,
    NULL, NULL, INTERNET_FLAG_EXISTING_CONNECT );
    }

    //sends request to get file.
    if (!pFile->SendRequest())
    {
    delete pFile;
    delete pConnect;
    return false;
    }
    .... some stuff removed; eventually the data is read with:
    fs.Open(strFile,CFile::modeCreate|CFile::modeWrite );
    dwRead = pFile->Read(buffer, READ_BUFFER_SIZE);
    while( dwRead > 0)
    {
    fs.Write(buffer,dwRead);
    dwRead = pFile->Read(buffer, READ_BUFFER_SIZE);
    }

    What I am doing wrong ?

    --Rob


  2. Re: How to download a binary file via http ?


    In article <1119294464.369840.279320@f14g2000cwb.googlegroups. com>, rgristroph@gmail.com writes:
    >
    > I am using MS VC++ 6.0, and I am using the CHttpConnection and
    > CHttpFile to download files from a web server. Everything is working
    > fine for ascii files.
    >
    > When I download a binary file I get a corrupted file, however.
    >
    > ...
    > fs.Open(strFile,CFile::modeCreate|CFile::modeWrite );


    I haven't used the CFile class myself, but have you tried that with
    "|CFile::typeBinary"? If it opens by default in text mode, then
    it'll translate "newline" characters (which I think for MSVC are
    0x0d, ie CR) to CR LF pairs as it writes. That will definitely
    corrupt your binary file, unless by chance it's free of 0x0d bytes.
    (MSVC might use LF, 0x0a, for newlines - I haven't checked - but the
    same principle applies.)

    --
    Michael Wojcik michael.wojcik@microfocus.com

    The lark is exclusively a Soviet bird. The lark does not like the
    other countries, and lets its harmonious song be heard only over the
    fields made fertile by the collective labor of the citizens of the
    happy land of the Soviets. -- D. Bleiman


  3. Re: How to download a binary file via http ?


    In article , mwojcik@newsguy.com (Michael Wojcik) writes:
    >


    .... a response to a two-month-old message. Sorry about that; I
    thought I had cleaned out the older messages from my unread list,
    but apparently not.

    --
    Michael Wojcik michael.wojcik@microfocus.com

+ Reply to Thread