To retrieve the file at the URL
http://www.somehost.com/path/file.html
first open a socket to the host www.somehost.com, port 80 (use the default port of 80 because none is specified in the URL). Then, send something like the following through the socket:
GET /path/file.html HTTP/1.0
From: someuser@tutorialspoint.com
User-Agent: HTTPTool/1.0
[blank line here]
|
The server should respond with something like the following, sent back through the same socket:
HTTP/1.0 200 OK
Date: Fri, 31 Dec 1999 23:59:59 GMT
Content-Type: text/html
Content-Length: 1354
<html>
<body>
<h1>Happy New Millennium!</h1>
(more file contents)
.
.
.
</body>
</html>
|
After sending the response, the server closes the socket.
To familiarize yourself with requests and responses, do manually experiment with HTTP using telnet.
Manually Experimenting with HTTP
Using telnet, you can open an interactive socket to an HTTP server.
This lets you manually enter a request, and see the response written
to your screen. It's a great help when learning HTTP, to see exactly how
a server responds to a particular request. It also helps when
troubleshooting.
From a Unix prompt, open a connection to an HTTP server with something like
telnet www.somehost.com 80
Then enter your request line by line, like
GET /path/file.html HTTP/1.0
[headers here, if any]
[blank line here]
After you finish your request with the blank line, you'll see the raw
response from the server, including the status line, headers,
and message body.
|