There are three commonly used HTTP methods
- GET
- POST
- HEAD
The GET method
The GET method is used to retrieve web pages from the server. It is a part of the request line from the client and tells the server to pass a copy of the document back to the browser or run a CGI program.
GET is also used to send user information from an online form on a web page to the server. Through this, the data is sent as a part of the URL in ‘name-value’ pairs.
Sponsored Links
The XHTML code code for a simple form would look something like this (XHTML is simply a slightly more advanced form of HTML):
<form name="myform" action="cgi-bin/validate.cgi" method="get"> First Name: <input type="text" name="fname" size="20" /><br /> Last Name: <input type="text" name="lname" size="20" /><br /> <input type="submit" value="SUBMIT" /> </form>
And this will be displayed in the browser as:
Now, let us suppose your name is John Doe. When you submit this form, the data is attached to the URL in name-value pairs. Each name-value pair is demarcated by a ‘&’ sign and the data is separated from the actual URL with a ‘?’ sign. Thus after submission the URL in the address/location bar of the browser will be as:
www.example.com/cgi-bin/validate.cgi?fname=John&lname=Doe
Note how the ? and & sign separate the URL from the data and the name-value pairs, respectively.
You can also call CGI programs by supplying data with the URL in an HTML link like:
<a href="http://www.somesite.com/cgi-program.cgi?name1 =value1&name2=value2>Link to somesite</a>
which shows up as:
If you move your mouse over this link, you will be able to see the URL and the attached data in the status bar of your browser.
The Post Method
Data from the POST method is sent by the client as a part of the request body. The server receives this data and sends it to a CGI program along with other variables. The METHOD attribute inside the <FORM> tag will carry POST as its value. The big advantage in using POST over GET is that the data is not open to prying eyes. Also, via GET, you can transfer only a limited amount of data; POST exerts no such limitations.
The Head METHOD
This method is used to find information about a document located on the server not retrieve it. It is very similar to the GET method except no data is returned by the server.