|
Contents of Request and Response
There is one last thing we need to know before we actually start looking at the various methods,and that is the contents of a request and a response.
A typical request,

A typical response,

You must have got a fair idea of how a client request and how a server response looks like.
Now let us get back to see each of the method one by one.
1. GET
GET is the default method of browser. If no method is specified them GET method is invoked.
Get method is used for retrieving the resource from the server,e.g. HTML page,image,sound file etc. All the client form data gets appended to the URL starting with a question mark ? e.g. http://visulabuilder.com/products/servlet./index.html?id=?09?
The main advantage of get is that the page can be bookmarked and sent without a form . However this also results in some drawback. There is a limit to how much data a client can send as most browser limit the URL length to about 255 characters.
Moreover a get method should not be used where it can make changes to the server side [e.g. update a database] unless the system requires so,because each time a client sends a get request,it will result in a server side change.
Only text data can be sent through a get request.
2. POST
Post method is a request for posting data to the server. It transfers data in the body rather than the URL as in get. Unlike the get method post can transfer theoretically limitless data. Post is more secure than get,and the client can send both text as well as binary data to the server.
3. PUT
Put is something like upload. Through a PUT method you can request to store static information on the server.
4. HEAD
Head request is used when the client does not want back a response body from the server. In such case only the status line is returned along with the header. The main argument in favour of using head method is when the client does not want a response body back. This situation could arise if the client only has to check that a particular resource exists on the server. Also since the response is smaller it helps to save bandwidth.
5. Delete
Delete is the opposite of put. It enables the client to remove the file from the URL
6. Option
This request method will result in a response being delivered from the server indicating all the allowable methods,the server supports.
Get post and head are the most frequently used HTTP methods.
|