Open In App

Which HTTP method is used to send the form-data ?

Last Updated : 09 May, 2023
Improve
Improve
Like Article
Like
Save
Share
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:

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:



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads