Thread: Starting download file (requests)?

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    1

    Starting download file (requests)?

    I have problem. I send Get request to serwer

    GET /file/file.rar HTTP/1.1
    Host: example.com
    User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10
    Accept: text/html,application/xhtml+xml,applicat...
    Accept-Language: pl,en-us;q=0.7,en;q=0.3
    Accept-Encoding: gzip,deflate
    Accept-Charset: ISO-8859-2,utf-8;q=0.7,*;q=0.7
    Keep-Alive: 300
    Connection: keep-alive
    Cookie: user=8888899-%26%26%26%25

    and i get response

    HTTP/1.1 200 OK
    P3P: CP="ALL DSP COR CURa ADMa DEVa TAIa PSAa PSDa IVAa IVDa CONa TELa OUR STP UNI NAV STA PRE"
    Date: Tue, 02 Jun 2009 11:20:59 GMT
    Connection: close
    Accept-Ranges: bytes
    Content-Type: text/html; charset=ISO-8859-1
    Cache-Control: no-cache
    Content-Encoding: gzip
    Content-Length: 2658

    What i have to do to start downloading this file?? im using recive function but server dont send file to me, i think i have to do something first

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by kaszynek View Post
    HTTP/1.1 200 OK
    P3P: CP="ALL DSP COR CURa ADMa DEVa TAIa PSAa PSDa IVAa IVDa CONa TELa OUR STP UNI NAV STA PRE"
    Date: Tue, 02 Jun 2009 11:20:59 GMT
    Connection: close
    Accept-Ranges: bytes
    Content-Type: text/html; charset=ISO-8859-1
    Cache-Control: no-cache
    Content-Encoding: gzip
    Content-Length: 2658

    What i have to do to start downloading this file?? im using recive function but server dont send file to me, i think i have to do something first
    You just did. The file is not sent to you in as a .gz file, it is sent as raw data in an internet packet. That is the header. The rest of that packet (the 2658 bytes of gobbledy-gook that followed) is the gzip file. You have strip the packet header/inet wrapper off and write that raw binary data (using fwrite) into a file. Then call it "myfile.gz" and voila! you downloaded a gzip file.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    im using recive function but server dont send file to me
    There is probably a problem with the way you are calling recv(). Can you post your code?

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by bithub View Post
    There is probably a problem with the way you are calling recv().
    Only if you have the message you posted but there was no 2658 bytes attached to it...which would be impossible. The server *did* send it, it *was* part of that packet.

    Again, you have to dissemble the packet. The server does not send a file, any file, as a discrete unit. It all arrives as a stream of data.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #5
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Only if you have the message you posted but there was no 2658 bytes attached to it...
    What?

    The server *did* send it, it *was* part of that packet.
    It was most certaintly not part of that packet considering the Content-Length is greater than a MTU.

  6. #6
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Quote Originally Posted by MK27 View Post
    You just did. The file is not sent to you in as a .gz file, it is sent as raw data in an internet packet. That is the header. The rest of that packet (the 2658 bytes of gobbledy-gook that followed) is the gzip file. You have strip the packet header/inet wrapper off and write that raw binary data (using fwrite) into a file. Then call it "myfile.gz" and voila! you downloaded a gzip file.
    He's not downloading a gzip file. He's attempting to download a .rar archive, that happens to be sent gzip encoded by the server. Really, it'll be more like myfile.rar.gz. However, notice the content-type: text/html - either the server is not sending back a rar file at all, and is sending back HTML, or the server is sending the wrong Content-Type. (Probably the former.)

    Quote Originally Posted by MK27
    Only if you have the message you posted but there was no 2658 bytes attached to it...which would be impossible. The server *did* send it, it *was* part of that packet.

    Again, you have to dissemble the packet. The server does not send a file, any file, as a discrete unit. It all arrives as a stream of data.
    No. The server sends a stream of data. From the client & servers point of view, packets are not involved. Whether the OP is actually getting this data into whatever buffer he may have, we cannot tell here, as he hasn't posted any code. The likely answer is that if he is, he is doing so by luck.
    If the OP would post his code invovling recv(), as bithub requested, we would be able to know a lot more about what is actually going on.
    Quote Originally Posted by bithub
    It was most certaintly not part of that packet considering the Content-Length is greater than a MTU.
    While yes, it is irrelevant. The OP may have captured all 2-3 thousand bytes in a single recv(). One recv() != one TCP/IP packet.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 10:47 AM
  3. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. 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