First of all, let's differentiate between GET
and POST
Get: It is the default HTTP
request that is made to the server and is used to retrieve the data from the server and query string that comes after ?
in a URI
is used to retrieve a unique resource.
this is the format
GET /someweb.asp?data=value HTTP/1.0
here data=value
is the query string value passed.
POST: It is used to send data to the server safely so anything that is needed, this is the format of a POST
request
POST /somweb.aspHTTP/1.0
Host: localhost
Content-Type: application/x-www-form-urlencoded //you can put any format here
Content-Length: 11 //it depends
Name= somename
Why POST over GET?
In GET
the value being sent to the servers are usually appended to the base URL in the query string,now there are 2 consequences of this
GET
requests are saved in browser history with the parameters. So your passwords remain un-encrypted in browser history. This was a real issue for Facebook back in the days.URI
can be. If have too many parameters being sent you might receive 414 Error - URI too long
In case of post request your data from the fields are added to the body instead. Length of request params is calculated, and added to the header for content-length and no important data is directly appended to the URL.
You can use the Google Developer Tools' network section to see basic information about how requests are made to the servers.
and you can always add more values in your Request Headers
like Cache-Control
, Origin
, Accept
.