C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Reply
 
LinkBack Thread Tools Display Modes
Old 06-02-2009, 07:10 AM   #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
kaszynek is offline   Reply With Quote
Old 06-02-2009, 08:03 AM   #2
subminimalist
 
MK27's Avatar
 
Join Date: Jul 2008
Location: NYC
Posts: 3,944
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.
__________________

Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS
MK27 is offline   Reply With Quote
Old 06-02-2009, 02:12 PM   #3
Registered User
 
Join Date: Sep 2004
Location: California
Posts: 2,845
Quote:
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?
bithub is offline   Reply With Quote
Old 06-02-2009, 03:39 PM   #4
subminimalist
 
MK27's Avatar
 
Join Date: Jul 2008
Location: NYC
Posts: 3,944
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.
__________________

Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS
MK27 is offline   Reply With Quote
Old 06-02-2009, 05:25 PM   #5
Registered User
 
Join Date: Sep 2004
Location: California
Posts: 2,845
Quote:
Only if you have the message you posted but there was no 2658 bytes attached to it...
What?

Quote:
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.
bithub is offline   Reply With Quote
Old 06-02-2009, 07:14 PM   #6
int x = *((int *) NULL);
 
Cactus_Hugger's Avatar
 
Join Date: Jul 2003
Location: Banks of the River Styx
Posts: 891
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)
Cactus_Hugger is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie homework help fossage C Programming 3 04-30-2009 04:27 PM
File Writing Problem polskash C Programming 3 02-13-2009 10:47 AM
Formatting a text file... dagorsul C Programming 12 05-02-2008 03:53 AM
Dikumud maxorator C++ Programming 1 10-01-2005 06:39 AM
Hmm....help me take a look at this: File Encryptor heljy C Programming 3 03-23-2002 10:57 AM


All times are GMT -6. The time now is 07:13 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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