Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Difference between HTTP GET and POST Methods

  • Last Updated : 22 Oct, 2021

HTTP GET: The Hypertext Transfer Protocol(HTTP) Get method is mainly used at the client (Browser) side to send a request to a specified server to get certain data or resources. Using this method the server should only let us receive the data and not change its state. Hence it is only used to view something and not to change it. Get method is one of the most used HTTP method. The request parameter of the get method is appended to the URL. Get request is better for the data which does not need to be secure (It means the data which does not contain images or word documents).

Example: In the following HTML code we have created a form with text field as Username and City. we have also included a PHP file getmethod.php where our data would be sent after we click the submit button.

index.html




<!DOCTYPE html>
<html>
  
<body>
    <form action="getmethod.php" method="GET">
        Username: <input type="text" 
            name="username" /> <br>
  
        City: <input type="text" 
            name="city" /> <br>
              
        <input type="submit" />
    </form>
</body>
  
</html>

In the following PHP code using the GET method we have displayed the Username and city.

 



getmethod.php




<!DOCTYPE html>
<html>
  
<body>
    Welcome
    <?php echo $_GET["username"]; ?> </br>
    Your City is:
    <?php echo $_GET["city"]; ?>
</body>
  
</html>

Output: Data passed in GET method is clearly visible in the address bar, which can compromise the security.

HTTP POST: The Hypertext Transfer Protocol(HTTP) Post method is mainly used at the client (Browser) side to send data to a Specified server in order to create or rewrite a particular resource/data. This data sent to the server is stored in the request body of the HTTP request. Post method eventually leads to the creation of a new resource or updating an existing one. Due to this dynamic use, it is one of the most used HTTP methods. It is not one of the most secure methods because the data that is been sent is included in the body of the request and not in the URL. Post request is better for the data which needs to be secure (It means the data which contains images or word documents).

Example: In the following HTML code we have created a form with text field as Username and Area of study. we have also included a PHP file postmethod.php, where our data would be sent after we click the submit button.

index.html




<!DOCTYPE html>
<html>
  
<body>
    <form action="postmethod.php" method="post">
        Username: <input type="text" 
            name="username" /> <br>
  
        Area of Study: <input 
            type="text" name="area" /> <br>
  
        <input type="submit" />
    </form>
</body>
  
</html>

In the following PHP code using the POST method we have displayed the Username and Area of study .

 



postmethod.php




<!DOCTYPE html>
<html>
  
<body>
    Welcome
    <?php echo $_POST["username"]; ?> </br>
    YOur Area of Study is:
    <?php echo $_POST["area"]; ?>
</body>
  
</html>

Output: Data passed in POST method is not shown in the address bar, which maintains the security.

Difference between HTTP GET and HTTP POST

HTTP GET

HTTP POST

In GET method we can not send large amount of data rather limited data is sent because the request parameter is appended into the URL. In POST method large amount of data can be sent because the request parameter is appended into the body.

GET request is comparatively better than Post so it is used more than the

Post request.

POST request is comparatively less better than Get so it is used less than the Get request.
GET request is comparatively less secure because the data is exposed in the URL bar.POST request is comparatively more secure because the data is not exposed in the URL bar.
Request made through GET method are stored in Browser history.Request made through POST method is not stored in Browser history.
GET method request can be saved as bookmark in browser.POST method request can not be saved as bookmark in browser.
Request made through GET method are stored in cache memory of Browser. Request made through POST method are not stored in cache memory of Browser.
Data passed through GET method can be easily stolen by attackers.Data passed through POST method can not be easily stolen by attackers.
In GET method only ASCII characters are allowed.In POST method all types of data is allowed.



My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!