HTTP (Hyper Text Transfer Protocol) is a stateless, text based network protocol that is designed for enabling communications between clients and servers by using request and response cycles. A client opens a connection and submits a request message to a server; then the server returns a response to that client. Because of the stateless nature, after delivering the response, the server closes the connection and does not maintain any information about connection.
The requests and responses are text based messages including some basic information about the request or response and some HTTP headers as well as application specific information requested or responded.
Sample HTTP Request:
The first line of the HTTP request is called the request line and consists of 3 parts:
- The first part is called as the “method” that indicates what kind of request this is. Most common methods are GET, POST and HEAD.
- The second part is called as the “path” that is generally the part of the url that comes after the host (domain).
- The third part is called as the “protocol” that part contains “HTTP” and the version number.
The remainder of the request contains HTTP headers as “Name: Value” pairs on each line. These contain various information about the HTTP request and your browser. For example, the “User-Agent” line provides information on the browser version and the Operating System you are using. “Accept-Encoding” tells the server if your browser can accept compressed output like gzip.
You may have noticed that the cookie data is also transmitted inside an HTTP header. And if there was a referring url, that would have been in the header too. Most of these headers are optional. This HTTP request could have been as small as this:
GET /index.html HTTP/1.1
Sample HTTP Response:
Upon receiving a request, server generates a response and transmits it to the client. A basic response as a sample is given below:
HTTP/1.1 200 OK
Date: Mon, 30 May 2015 01:01:01 GMT
Server: Apache/126.96.36.199 (Unix) (Red-Hat/Linux)
Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT
Content-Type: text/html; charset=UTF-8
Hello World, this is a very simple HTML document.
GET: Requests data from a specified resource
- Data are restricted to ASCII codes
- All data is visible in the URL
- GET requests can be cached
- GET requests remain in the browser history
- GET requests can be bookmarked
- GET requests should never be used when dealing with sensitive data
- GET requests have length restrictions since URL lengths are limited depending on both client and server (max URL length is 2048 characters)
- GET requests should be used only to retrieve data
- Encoding type is “application/x-www-form-urlencoded”
POST: Submits data to be processed to a specified resource
Request data is sent in the HTTP message body of a POST request.
Binary data can be transmitted
POST requests are never cached
POST requests do not remain in the browser history
POST requests cannot be bookmarked
POST requests have no restrictions on data length
Encoding type is “application/x-www-form-urlencoded” or “multipart/form-data” for binary data
Other HTTP Request Methods
|HEAD||Same as GET but returns only HTTP headers and no document body|
|PUT||Uploads a representation of the specified URI|
|DELETE||Deletes the specified resource|
|OPTIONS||Returns the HTTP methods that the server supports|
|CONNECT||Converts the request connection to a transparent TCP/IP tunnel|