Which HTTP method is used to send the form-data ? - GeeksforGeeks (2024)

Improve

Improve

Like Article

Like

Save

Report

In this article, we will learn the HTTP method to send the form data. Before diving into this topic, we need to know what exactly is the HTTP method and how many HTTP methods available.

What is HTTP?

The HTTP stands for HyperText Transfer Protocol. It is used to communicate between clients and servers. It works on a request-response protocol between client and server. The client sends a request to the server. The server accepts the request and returns a response to the client. It can be information about the request and requested content.

These are the following most commonly used HTTP methods.

  • GET
  • POST

After validation of the form on the client-side, It is ready to submit the form. After submission, the form data send to the server using the GET method and the POST method. Once we will use the GET method to send the form data to the server then we will use the POST method to send the form data to the server. In the end, we will understand the difference between both HTTP methods that are used to send the form data.

Sending the form data using the ‘GET’ HTTP method: The GET method is used to request data from specified resources. It sends an empty body to the server and asks to get resources. If the form data is sent using the GET method the data sent by the server is appended to the URL of the page. Its requests have some length restrictions. It is not used for modification.

Example: In this example, we will send the data using GET method

HTML

<!DOCTYPE html>

<html>

<body>

<h1>Send data using the 'GET' HTTP method</h1>

<form action="" method="get" target="_blank">

<label>User Name:</label>

<input type="text" id="username"

name="User Name"><br><br>

<label>Password:</label>

<input type="password" id="password"

name="Password"><br><br>

<input type="submit" value="Login">

</form>

</body>

</html>

Output:

Which HTTP method is used to send the form-data ? - GeeksforGeeks (1)

Sending the form data using the ‘POST’ HTTP method: The POST method is used to send data to a server to create and update a resource. The requested data using the POST method is appended to the body of the HTTP request rather than the page URL. Its request has no restrictions on data length.

Example: In this example, we will send data using POST method.

HTML

<!DOCTYPE html>

<html>

<body>

<h2>Send data using the 'POST' HTTP method</h2>

<form action="" method="post" target="_blank">

<label>User Name:</label>

<input type="text" id="username"

name="User Name"><br><br>

<label>Password:</label>

<input type="password" id="password"

name="Password"><br><br>

<input type="submit" value="Login">

</form>

</body>

</html>

Output:

Which HTTP method is used to send the form-data ? - GeeksforGeeks (2)



Last Updated : 09 May, 2023

Like Article

Save Article

Share your thoughts in the comments

Please Login to comment...

Which HTTP method is used to send the form-data ? - GeeksforGeeks (2024)
Top Articles
Latest Posts
Article information

Author: Tyson Zemlak

Last Updated:

Views: 5505

Rating: 4.2 / 5 (63 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Tyson Zemlak

Birthday: 1992-03-17

Address: Apt. 662 96191 Quigley Dam, Kubview, MA 42013

Phone: +441678032891

Job: Community-Services Orchestrator

Hobby: Coffee roasting, Calligraphy, Metalworking, Fashion, Vehicle restoration, Shopping, Photography

Introduction: My name is Tyson Zemlak, I am a excited, light, sparkling, super, open, fair, magnificent person who loves writing and wants to share my knowledge and understanding with you.