+3 votes
296 views
in Web development by (242k points)
reopened
GET vs. POST: the two most popular face-to-face HTTP request methods

1 Answer

+4 votes
by (1.6m points)
edited
 
Best answer

HTTP request methods: GET
HTTP request methods: POST
Comparison between GET and POST methods
When to use one or the other?
GET advantages
Disadvantages of GET
POST advantages
Disadvantages of POST

image

GET vs. POST: the two most popular face-to-face HTTP request methods

In today's web pages, clients (also called browsers) not only get an HTML element from the server, but also send information like the following:

  • The search text that the user has entered in the search engine
  • The content of the forms
  • The selection filter in online stores
  • The order of a list

To send certain types of information to the server, the HTTP protocol provides different request methods . The two most important are GET and POST, which, although they give the same results, reveal some differences between them. Read below what these differences are and when to use one or the other..

advice

If you want to learn more about request methods in general, don't miss our article on HTTP requests in our guide.

Index
  1. HTTP request methods: GET
    1. GET advantages
    2. Disadvantages of GET
  2. HTTP request methods: POST
    1. POST advantages
    2. Disadvantages of POST
  3. Comparison between GET and POST methods
  4. When to use one or the other?

HTTP request methods: GET

With the GET method, the data that is sent to the server is written to the same URL . In the browser window, you will find it like this:

  www.ejemplo.com/registrarse.php?nombre=pedro&apellido=perez&edad=55&genero=hombre  

All information entered by the user (the so-called "URL parameters") is conveyed as openly as the URL itself. This has advantages and disadventages..

GET advantages

URL parameters can be saved alongside the URL as a bookmark . In this way, you can enter a search and later consult it again easily. The page can also be accessed again through the browser history.

This is useful, for example, if you regularly visit the same place on Google Maps or if you save web pages with specific filter settings..

Disadvantages of GET

The biggest disadvantage of the GET method is its weak data protection . The URL parameters that are sent are visible in the browser's address bar and are accessible without a password in the browsing history, in the cache and in the servers' log .

Another disadvantage is that its capacity is limited : depending on the server and the browser, it is not possible to enter more than 2000 characters. Also, URL parameters can only contain ASCII characters (letters, numbers, signs, etc.) and not binary data such as audio files or images.

HTTP request methods: POST

The POST method enters the parameters in the HTTP request for the server. Therefore, they are not visible to the user. Also, the capacity of the POST method is unlimited.

POST advantages

When it comes to data, such as filling in forms with usernames and passwords, the POST method offers a lot of discretion . The data is not shown in the cache or in the browsing history. The flexibility of the POST method is also very useful: not only can you send short texts, but also other types of information, such as photos or videos.

Disadvantages of POST

When a web page containing a form is refreshed (for example, when you go back to the previous page) the form data needs to be transferred again (you may have received one of these warnings once). For this reason, there is a risk that the data is sent multiple times by mistake, which, in the case of an online store, can lead to duplicate orders. However, modern store websites are usually prepared to avoid this type of problem.

Also, data transferred with the POST method cannot be saved alongside the URL as a bookmark .

Comparison between GET and POST methods

  GET POST
Visibility Visible in the address bar for the user Invisible to the user
Bookmarks and browsing histories URL parameters are saved next to the URL URL parameters are not saved next to URL
Cache and server log URL parameters are saved unencrypted. URL parameters are not automatically saved
Behavior when updating the browser or going back URL parameters are not sent again The browser warns that the form data will be sent again
Type of data ASCII characters only ASCII characters and binary data
Data length Limited to the maximum of the URL (2048 characters) Unlimited

When to use one or the other?

The POST method is advisable when the user must send data or files to the server, such as when filling in forms or uploading photos.

The GET method is suitable for customizing web pages: the user can save searches, filter settings and list sorting next to the URL as bookmarks, so that on his next visit the web page will be displayed according to his preferences.

In summary:

  • GET for web page configuration (filters, sorting, searches, etc.)
  • POST for the transfer of information and data

...