Difference between GET and POST methods in HTTP request


This tutorial explains the difference between GET and POST methods of HTTP request in detail.
 
GET is a simple request, POST can send user data

GET is the simplest HTTP method, and its main job in life is to ask the server to get a resource and send it back. That resource might be an HTML page, a JPEG, a PDF, etc. Doesn't matter. The point of GET is to get something back from the server.

POST is a more powerful request. It's like a GET plus plus. With POST, you can request something and at the same time send form data to the server.

It's true... you can send a little data with HTTP GET

But you might not want to. Reasons you might use POST instead of GET include:

  • The total amount of characters in a GET is really limited (depending on the server). If the user types, say, a long passage into a "search" input box, the GET might not work.
  • The data you send with the GET is appended to the URL up in the browser bar, so whatever you send is exposed. Better not put a password or some other sensitive data as part of a GET!
  • Because of number two above, the user can't bookmark a form submission if you use POST instead of GET. Depending on your app, you may or may not want users to be able to bookmark the resulting request from a form submission.

Anatomy of an HTTP GET request

The path to the resource, and any parameters added to the URL are all included on the request line".




Anatomy of an HTTP POST request

HTTP POST requests are designed to be used by the browser to make complex requests on the server. For instance, if a user has just completed a long form, the application might want all of the form's data to be added to a database. The data to be sent back to the server
is known as the "message body" or "payload" and can be quite large.


 

No comments:

Post a Comment