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

The Future is Here: How the Shipping Industry is Revolutionizing the Global Economy

The naval sector is a true global economic power, which has navigated towards a 150 billion market...

May 1, 2024

Publishers and OpenAI sign agreements to regulate the flow of information processed by Artificial Intelligence

Last Monday, the Financial Times announced a deal with OpenAI. FT licenses its world-class journalism…

April 30 2024

Online Payments: Here's How Streaming Services Make You Pay Forever

Millions of people pay for streaming services, paying monthly subscription fees. It is common opinion that you…

April 29 2024

Veeam features the most comprehensive support for ransomware, from protection to response and recovery

Coveware by Veeam will continue to provide cyber extortion incident response services. Coveware will offer forensics and remediation capabilities…

April 23 2024