Tuesday, April 21, 2009

Difference between "GET" and "POST"

Technical difference according to HTML specification is, when "GET" is used the form data is encoded(by browser) in to URL whereas in "POST" the data is to appear with in the message body.According to the usage recommendation giving in the specification the "GET" should be used the when the form processing is "idempotent", which mean "GET" is used for the purpose of data retrieving whereas "POST" may be used when service associated with the processing of a form has a side effects like storing or updating data, sending email or ordering products.

Difference in server side processing

As the data is encoded in different way depending on whether it is send by GET or POST, different decoding algorithm is needed which may require some changes in the script that processes the form submission. For example, when using the CGI interface if the method is "GET" the data is received in environmental variable, whereas it is received in standard input when the method is "POST".

Some exceptions were "POST" can be used for idempotent queries

  • Method "GET" is inapplicable if the data present on form is non-Ascii, so using the POST in this case is less dangerous.

  • Method "GET" can not handle long URL so if the from data set is large comprises of hundreds of character, using the POST is advisable.

  • Method "POST" can be used in order to make it less visible to user how the the form queries but its not very effective as it just prevent user from seen the form data in the URL from the user, however user can see the source code of form element.

No comments:

Post a Comment