WebDevelopersNotes logo

home-icon Home / Basics / HTTP Client Methods – GET and POST

HTTP Client Methods – GET and POST

HTTP Client Methods – GET and POST

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:

First Name:
Last Name:

Note: Submit button does not work here!

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&gt;Link to somesite</a>

which shows up as:

Link to example.com

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.

Sponsored Links

Your comments
Star icon IMPORTANT Have a question / problem? Click here to ask an expert.

Why should you delete web browser history?

Sponsored Links

Tips

How do I view a deleted web page?
Is there a way to view a deleted web page - one that is no longer available? Yes there is and the solution is quite simple. [more...]

Fact

IMDb's first film-related advertising campaign was for the movie Independence Day. [more...]

We use cookies to give you the best possible website experience. By using WebDevelopersNotes.com, you agree to our Privacy Policy