Link to home
Start Free TrialLog in
Avatar of gambito042797
gambito042797

asked on

Getting a file from another host in C

I want that my C program reads a file located in another host,  passing it  the URL location as parameter.
Avatar of pxh
pxh

What server function does the other host have?
Avatar of gambito042797

ASKER

I need the necesary instructions to make my program behaves as does a browser. For example, if you type in a browser http://www.host.xxx/path/filename.gif, then you get in the browser that file, wathever SO and functions the server you adressed has, well, that server must have a Web Server serving those files. I think this must be done by doing that my program send a CGI request such as

GET /docX.html HTTP/1.0
Accept: www/source
Accept: text/html
Accept: image/gif
User-Agent:  Lynx/2.2  libwww/2.14
From:  myname@myhost.xxx
     * blank line *

and then the program must receive an answer from the server similar to this one:

HTTP/1.0 200 OK
Date: Monday, 02-Feb-96 23:04:12 GMT
Server: NCSA/1.1
MIME-version: 1.0
Last-modified: Monday, 15-May-96 23:33:16 GMT
Content-type: text/html
Content-length: 2345
     * blank line *
<HTML><HEAD><TITLE> . . . the HTML page


I do know how to implement the server CGI part, but what I want is to implement the client behavior in my program (not a full browser, only be able to get a file from another server), that is, how does my program has to send the request and how does it has to wait for the answer.


This just involves a bit of socket programming - it's like a client which telnets to port 80 of a server machine.

But, are you aware that, when a web server sends, say, an image, it usually sends it encoded?

-julio
Yes, I've put above the encoding. The difference in image files is the line Content-type that will be:

Content-type: image/gif

and after the blank line will come the binary data of the file instead of the code for an html page. But thanks.
ASKER CERTIFIED SOLUTION
Avatar of julio011597
julio011597

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It worked!!!  I changed  the host and the path and worked fine.
Thanks a lot Julio.