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:
GET
: Used to request data from a specified resourcePOST
: Used to send data to a server to update a resourceGET
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 ?
.
From the URL, the server can parse the value submitted by the user where:
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.
GET
e POST
in comparisonErcole Palmeri
The naval sector is a true global economic power, which has navigated towards a 150 billion market...
Last Monday, the Financial Times announced a deal with OpenAI. FT licenses its world-class journalism…
Millions of people pay for streaming services, paying monthly subscription fees. It is common opinion that you…
Coveware by Veeam will continue to provide cyber extortion incident response services. Coveware will offer forensics and remediation capabilities…