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:
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..
If you want to learn more about request methods in general, don't miss our article on HTTP requests in our guide.
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..
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..
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.
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.
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.
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 .
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: