GET vs.​ POST

Both the GET and POST methods are used to transfer data from a client to a server in HTTP protocol.

The Hypertext Transfer Protocol (HTTP) enables communications between clients and servers. It works as a request-response protocol between the client and the server for an exchange of data.

  • GET: The GET method requests data from a specified resource.
  • ​POST: The POST method submits the processed data to a specified resource.

Functional differences​

The POST method supplies additional data from the client (usually a web browser) to the server in the message body. A sample POST request has a message body that looks something like this:

POST /sample/my_form.php HTTP/1.1
Host: educative.io
param1=item1&param2=item2
A HTTP request using POST method.
A HTTP request using POST method.

In contrast, the GET method includes all the data required by the server in the URL. All of the data that​ is to be sent is appended to the URL as query string parameters. A sample GET request looks something like this:

educative.io/sample/my_form.php?name=form_name&number=form_number
A HTTP request using GET method.
A HTTP request using GET method.

The following table summarizes other differences between GET and POST:

GET POST
Bookmarked Can be bookmarked and cached. Can neither be bookmarked nor cached.
Data Length Data length is usually restricted ​to 2048 characters. No restrictions on the amount of data that can be sent.
Data type Only Ascii characters allowed. Binary data is also allowed.
Security GET is less secure than POST because sent data is part of the URL. POST is a little safer than GET because the parameters are stored neither in the browser history nor in the web server logs.

Copyright ©2024 Educative, Inc. All rights reserved