Downloading a file though HTTP requests

This is a discussion on Downloading a file though HTTP requests within the Windows Programming forums, part of the Platform Specific Boards category; i'm trying to download a zip file from a website, i think i have the request structured properly but there ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    81

    Downloading a file though HTTP requests

    i'm trying to download a zip file from a website, i think i have the request structured properly but there something wrong because when i try and open the file it says its an invalid arcive

    here the code i have to send and recieve the data
    Code:
        case FD_READ:
          {
            FILE *in;
            in = fopen("testing.zip","a+");
            ret = recv(wParam,recved,sizeof(recved),0);
            fprintf(in,recved);
            fclose(in);
            return TRUE;
          }
        case FD_WRITE:
          {
            char request[] = "GET /files/apps/htmlgen.zip HTTP/1.1\r\nHost: misdomain.tripod.com\r\nAccept: */*\r\nUser-Agent: Download Gopher/1.0\r\nPragma: no-cache\r\nCache-Control: no-cache\r\nConnection: close\r\n\r\n";
            ret = send(wParam,request,strlen(request),0);
            return TRUE;
          }
    when i view the file afterwards this is at the top
    HTTP/1.1 200 OK

    Date: Sun, 25 May 2003 02:09:25 GMT

    Server: Squeegit/1.2.5 (3_sir)

    Set-Cookie: CookieStatus=COOKIE_OK; path=/; domain=.tripod.com; expires=Mon, 24-May-2004 02:09:25 GMT

    P3P: policyref="http://www.lycos.com/w3c/p3p.xml", CP="IDC DSP COR CURa ADMa DEVa CUSa PSAa IVAa CONo OUR IND UNI STA"

    Set-Cookie: CookieStatus=COOKIE_OK; path=/; domain=.tripod.com; expires=Mon, 24-May-2004 02:09:25 GMT

    Last-Modified: Sat, 17 May 2003 00:00:31 GMT

    ETag: "a53702-989d-3ec57b9f"

    Accept-Ranges: bytes

    Content-Length: 39069

    Connection: close

    Content-Type: application/zip
    so i delete that portion from the file and save it but it says its an invalid archive, can anyone see what i'm doing wrong

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    81
    still doesn't work,any other ideas?

  3. #3
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Code:
    in = fopen("testing.zip","a+");
    You're opening this in text mode (as you don't specify binary). In that case, you will screw up all kinds of non-printable characters that would appear in the file.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    81
    that fixed it, thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-22-2008, 12:19 AM
  2. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 03:29 PM
  3. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 08:51 PM
  4. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 10:57 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21