Articles

The actions of the FORM modules: POST and GET

The attribute method in the element <form> specifies how data is sent to the server.

HTTP methods declare what action should be performed on data sent to the server. The HTTP protocol provides several methods, and the HTML Form element is capable of using two methods to submit user data:

  • Method GET : Used to request data from a specified resource
  • Method POST : Used to send data to a server to update a resource

The method GET

The HTML GET method is used to get a resource from the server. 

For example:

<form method="get" action="www.bloginnovazione.it/search">
    <input type="search" name="location" placeholder="Search.." />
    <input type="submit" value="Go" />
</form>

When we confirm the above form, entering Italy in the input field, the request sent to the server will be www.bloginnovazione.it/search/?location=Italy.

The HTTP GET method adds a query string to the end of the URL to send the data to the server. The query string is in the form of a pair key=value preceded by the symbol ? .

Innovation newsletter
Don't miss the most important news on innovation. Sign up to receive them by email.

From the URL, the server can parse the value submitted by the user where:

  • key - location
  • value -Italy

The method POST

HTTP POST method is used to send data to server for further processing. For instance,

<form method="post" action="www.bloginnovazione.it/search">
    <label for="firstname">First name:</label>
    <input type="text" name="firstname" /><br />
    <label for="lastname">Last name:</label>
    <input type="text" name="lastname" /><br />
    <input type="submit" />
</form>

When we submit the form, it will add the user input data to the body of the request sent to the server. The request will be filled out as follows:

POST /user HTTP/2.0
Host: www.bloginnovazione.it
Content-Type: application/x-www-form-urlencoded
Content-Length: 33

firstname=Robin&lastname=Batman

The data sent is not easily visible to the user. However, we can control the submitted data using special tools such as browser developer tools.

Methods GET e POST in comparison

  • The GET method
    • The data sent with the GET method is visible in the URL.
    • GET requests can be bookmarked.
    • GET requests can be cached.
    • GET requests have a character limit of 2048 characters.
    • Only ASCII characters are allowed in GET requests.
  • The POST method
    • Data sent with the POST method is not visible.
    • POST requests cannot be bookmarked.
    • POST requests cannot be cached.
    • POST requests have no limit.
    • All data is allowed in the POST request

Ercole Palmeri

Innovation newsletter
Don't miss the most important news on innovation. Sign up to receive them by email.
Tags: html

Latest Articles

UK antitrust regulator raises BigTech alarm over GenAI

The UK CMA has issued a warning about Big Tech's behavior in the artificial intelligence market. There…

April 18 2024

Casa Green: energy revolution for a sustainable future in Italy

The "Green Houses" Decree, formulated by the European Union to enhance the energy efficiency of buildings, has concluded its legislative process with…

April 18 2024

Ecommerce in Italy at +27% according to the new Report by Casaleggio Associati

Casaleggio Associati's annual report on Ecommerce in Italy presented. Report entitled “AI-Commerce: the frontiers of Ecommerce with Artificial Intelligence”.…

April 17 2024

Brilliant Idea: Bandalux presents Airpure®, the curtain that purifies the air

Result of constant technological innovation and commitment to the environment and people's well-being. Bandalux presents Airpure®, a tent…

April 12 2024