Monday 21 February 2011

The Structure of HTTP Request

An HTTP message sent by client to server is called HTTP request.
The initial line for an HTTP request has three parts, separated by spaces.
  • A method name.
  • The local path of the requested resource(URI)
  • The version of HTTP being used.
A typical request is : GET /reports/sales/index.html HTTP/1.0

Here GET is the method name, /reports/sales/index.html is the resouce URI, and HTTP/1.0 is the HTTP version of the request.

The method name specifies the action that the client is requesting the server to perform.
HTTP 1.0 requests can have only one of the following three methods GET, HEAD, or POST.
HTTP 1.1 adds five more : PUT, OPTIONS, DELETE, TRACE, and CONNECT.

GET:
The HTTP GET method is used to retrieve a resource. It means " GET THE RESOURCE IDENTIFIED BY THIS URI". The resource is usually passive resource . A GET method request may be used for an active resource if there are few or no parameters to be passed.
If parameters are required, they are passed by appending a query string to the URI. For example,

GET method of HTTP Request
HEAD:
An HTTP HEAD request is used to retrieve the meta-information about a resource. Therefore, the response for a HEAD request contains only the header.
The Structure of HEAD request is exactly same as that of a GET request.
HEAD is commonly used to check the time when the resource was last modified on the server before sending it to the client. A HEAD request can save a lot of bandwidth, especially if the resource is very big.

POST:
A POST request is used to the server in order to be processed. It means, " POST THE DATA TO THE ARCHIVE RESOURCES IDENTIFIED BY THIS URI." The block of data is sent in message body.

HTML pages use POST to submit the HTML FORM data. Figure below shows the example of HTTP POST request generated by a typical form submission.

Example of HTTP POST request


PUT:
A PUT Request is used to add a resource to the server. It means"PUT THE DATA SENT IN THE MESSAGE BODY AND ASSOCIATE IT WITH THE GIVEN REQUEST-URI."

For Example, when we PUT a local file named sample.html to the server myhome.com using the URI http://www.myhome.com/files/example.html, the file becomes a resource on that server and is associated with the URI
http://www.myhome.com/files/example.html.






No comments:

Post a Comment