Hypertext transfer protocol

The purpose of this page is to explore the http protocol. Enter requests, headers and data below, and see server responses.


This page could be mis-used, since it could be used to submit requests to a server anonymously. To counter this, when you click the button, the following data will be recorded in a database table. This data will only be used in the event of an abuse report.

Your IP address: 38.103.63.55
Your hostname: 38.103.63.55
Your user-agent: CCBot/1.0 (+http://www.commoncrawl.org/bot.html)
Time now: Wednesday 07th of January 2009 04:55:30 AM
Host The hostname to send the HTTP request to
Request The request - see commands below
Header 1 Header fields - see below
Header 2
Header 3
Header 4
Header 5
Header 6
Header 7
Data

When you click the above button, a PHP script will try to open a socket to the host, on port 80, the standard http port. If the socket does open, it will then send your request, followed by your headers (all non-blank ones, in the order shown here), then a blank line, then your data (if any). The host's response (headers and any data) will be shown, or an error message if the socket cannot be opened.


HTTP

HTTP is a request-response protocol. In other words a client sends a request to a server (usually this is a browser requesting a web page from a server) then the server sends a response - the web page (plus a bit)

The request consists of a command (like GET to fetch a page), followed by some header fields providing more information - such as what kind of browser it is. There is then a blank line, then there may some data - for example if a form is being submitted

The server response on the first line has the HTTP version, then a code (such as 200) and what it means (OK). Then there are some header fields (such as the date and time, and a blank line. Then there is the data - usually the page which was requested, in html.

HTTP 1.1

There was a very early version 0.9 prior to 1992. Version 1.0 of HTTP started around 1992 and was completed in 1996, when it was superceded by 1.1.

There are 2 common requests - GET and POST. GET asks for a 'resource' commonly a webpage, while POST also supplies some data, usually coming froma completed form.

One change in 1.1 was that more than one host (like www.waltermilner.com) could live at the same IP address. The socket is opened on an IP address, so the server needs some way of knowing which host is being referred to. This is resolved using the Host: header

For example

GET /index.htm HTTP/1.1
Host: www.waltermilner.com
Connection: close

followed by a blank line, asks for the page index.htm. The GET and HTTP should be in capitals. Try it. The server will respond with OK (or not), other headers, a blank line, then the page

HEAD is the same as GET, except you only get the headers, not the data body. The purpose is for diagnostics, so its not often used

POST is to send data to a script on the server. When you fill in a form on the Internet and click Submit, the browser sends a POST request to a script which will handle the data. This data is 'URL-encoded' which means it is a sequence of name-value pairs, like "ProductCode=392&Quantity=4" when you buy 4 products with code 392.

For example

POST /learnhttp/post.php HTTP/1.1
Host: www.waltermilner.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 7
Connection: close

x=3&y=4

Means POST some data to file /learnhttp/post.php using HTTP 1.1
at www.waltermilner.com
expect the data to be url-encoded
and to be 7 bytes long
do it now
blank line ends headers - data follows
data is 2 pairs - x is 3 and y is 4

In fact post.php is a script which just echoes back the name value pairs which have been POSTed to it