What is HTTP
HTTP (Hypertext Transfer Protocol) is the communication protocol used to transfer HTML (HTML being the hypertext being transferred). Although it isn't used just for transferring the HTML page - it is also used to transfer other files needed to display the page, including style sheets, images and icons.
The HTTP protocol consists of request messages and response messages. Both the request and response contain HTTP headers and optional data content.
The request headers contain information about the request. This information specifies things like which version of the HTTP protocol to use, what data types the browser can accept, what browser is being used and which operating system it is running on. An example of an HTTP request is shown below:
GET / HTTP/1.1 Host: www.webdnstools.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:220.127.116.11) Gecko/20100722 Firefox/3.6.8 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Proxy-Connection: keep-alive
An HTTP response header contains information about the response. This includes the HTTP response code indicating the status of the request. Common response codes are 200 (OK), 301 (Moved Permanently), 302 (Found) and 404 (Not Found). After the header is a blank line, followed by any additional data. If an HTML page is being returned, the HTML data would be in the data sections of the response. An example of an HTTP response that returns an HTML page is shown below:
HTTP/1.1 200 OK Date: Fri, 08 Jul 2011 04:53:08 GMT Server: Apache Connection: close Transfer-Encoding: chunked Content-Type: text/html 75 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> ... </head> <body> ... </html> 0
In the response shown above, the HTML text is chunked. Each chunk is preceeded with a hexadecimal number representing the number of bytes in the chunk.