The Wayback Machine - https://web.archive.org/web/20241113123510/https://www.geeksforgeeks.org/difference-between-http-get-and-post-methods/
Open In App

Difference between HTTP GET and POST Methods

Last Updated : 16 Sep, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

HTTP (Hypertext Transfer Protocol) specifies a collection of request methods to specify what action is to be performed on a particular resource. The most commonly used HTTP request methods are GET, POST, PUT, PATCH, and DELETE. This article covers the 2 most common HTTP request methods, i.e. the GET & POST Methods among the rest of the methods.

HTTP GET

The HTTP GET method requests data from a server without altering its state. It appends parameters to the URL, making it suitable for retrieving non-sensitive data. Commonly used for viewing content, GET is ideal for requests that don’t involve data modification.

Example: In the following HTML code we have created a form with text fields such 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 HTTP POST method sends data from the client to the server to create or update resources, storing data in the request body. It’s suitable for secure data transfer, like images or documents, with security relying on encryption (HTTPS), authentication, and validation.

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 of some number of characters 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 method, so it is used less than the Get request.
GET requests are only used to request data (not modify)POST requests can be used to create and modify data.
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 as the data is visible to everyone.GET requests should never be used when dealing with sensitive dataData passed through POST method can not be easily stolen by attackers as the URL Data is not displayed in the URL
In GET method only ASCII characters are allowed.In POST method all types of data is allowed.
In GET method, the Encoding type is application/x-www-form-urlencoded In POSTmethod, the encoding type is application/x-www-form-urlencoded or multipart/form-data. Use multipart encoding for binary data

HTTP GET and POST Methods – FAQs

How are data sent in HTTP GET and POST requests?

GET sends data appended to the URL as query parameters, while POST sends data in the request body.

Is HTTP GET or POST more secure?

POST is generally more secure as it sends data in the body, but true security depends on using HTTPS for both methods.

Which method should I use for submitting forms: GET or POST?

Use GET for simple, non-sensitive data retrieval, and POST for forms involving sensitive data or changes to server-side resources.

Can HTTP GET requests change server state?

No, GET requests are intended for data retrieval without modifying the server state.

Why is POST preferred over GET for sending large amounts of data?

POST can handle large data in the request body, whereas GET is limited by URL length restrictions.



Similar Reads

HTTP GET and POST Methods in PHP
In this article, we will know what HTTP GET and POST methods are in PHP, how to implement these HTTP methods & their usage, by understanding them through the examples. HTTP: The Hypertext Transfer Protocol (HTTP) is designed to enable communications between clients and servers. HTTP works as a request-response protocol between a client and serv
4 min read
Difference between GET and POST Methods in HTML Form
When you submit a form on a website, using the GET method puts the data in the web address. The POST method sends the data quietly in the background, like a secret message that's not shown in the web address. GET MethodData in URL: GET sends form data as part of the URL and Information is visible in the browser's address bar.Bookmarking and Caching
1 min read
Difference between PUT and POST HTTP Request in Express and Postman
Both PUT and POST are request methods used in the HTTP protocol. In this article, we will introduce the HTTP methods such as PUT and POST in detail, and we will also discuss in detail when to use PUT and when to use POST. Table of Content PUT methodPOST MethodDifference between PUT and POST methodConclusionPUT methodPUT is one of the HTTP request m
6 min read
GET and POST Requests using Fetch API with Custom HTTP Library
This tutorial covers the basics of using the Fetch API to perform GET and POST requests within a custom HTTP library. Wiasynchronous operations and handling JSON data, you can effectively fetch data from remote APIs and submit data to servers. This approach gives you greater control and flexibility in managing HTTP requests and responses in your we
3 min read
How to use an HTTP GET or POST for Ajax Calls?
Sending an HTTP request to the server using AJAX is the most common way of fetching data these days. It provides us with methods to send and receive data. In this article, we are going to discuss GET and POST methods. GET method: This method is used to GET or RECEIVE the data from a file, API, etc. How to use GET method?To use the GET method, first
3 min read
Difference between HTTP/2 and HTTP/1.1
HTTP stands for hypertext transfer protocol & it is used in client-server communication. By using HTTP user sends the request to the server & the server sends the response to the user. There are several stages of development of HTTP but we will focus mainly on HTTP/1.1 which was created in 1997 & the new one is HTTP/2 which was created
3 min read
Difference between GET and POST request in Vanilla JavaScript
In this article, we will learn about the GET & POST request method in vanilla Javascript, & will also understand these 2 methods through the examples. GET and POST is two different types of HTTP request methods. HTTP protocol supports many methods to transfer data from the server or perform any operation on the server. The HTTP protocol sup
3 min read
Difference between app.get() and app.post() in Express.js.
In ExpressJS, app.get() and app.post() are two different methods used to handle HTTP requests but for different purposes. app.get() in ExpressJS:app.get() is used to handle incoming GET requests. GET requests are commonly used for fetching data from the server. For example, when you open a website in your browser, you are making a GET request to re
2 min read
Why are HTTP cookies used by Node.js for sending and receiving HTTP cookies?
The HTTP protocol is one of the most important protocols of the Application layer of the OSI model. The main use of this protocol is for sending hypertext information to the client to the server and server to the client to communicate on the World Wide Web. But, the HTTP protocol is a stateless protocol which means that this protocol cannot maintai
5 min read
POST request using AJAX by making Custom HTTP library
The task is to show how the XMLHttpRequest can be used to POST data to an API by making custom HTTP library. We will be taking a fake API which will contain Array of objects as an example and from that API we will show to POST data by XMLHttpRequest method by making a custom HTTP library. Used API: https://jsonplaceholder.typicode.com/posts What is
4 min read
How to Send an HTTP POST Request in JS?
We are going to send an API HTTP POST request in JavaScript using fetch API. The FetchAPI is a built-in method that takes in one compulsory parameter: the endpoint (API URL). While the other parameters may not be necessary when making a GET request, they are very useful for the POST HTTP request. The second parameter is used to define the body (dat
2 min read
How Are Parameters Sent In An HTTP POST Request?
HTTP POST requests are widely used in web development to send data from a client to a server. Whether you're submitting a form, uploading a file, or sending JSON data via an API, understanding how parameters are sent in an HTTP POST request is important. In this article, we’ll explore how are parameters sent in an HTTP POST request. What Is an HTTP
5 min read
How HTTP POST requests work in Node ?
The HTTP POST method is employed by the World Wide Web to send data to a server. This request method is characterized by the inclusion of data in the request body, and the type of this body is specified by the Content-Type header. Express.js, a web application framework for Node, facilitates the creation of servers and handling various HTTP request
3 min read
Will the 'error' event ever be emitted on 'http.IncomingMessage' in a node.js http.request ?
In this article, we will see how to handle the 'error' event that is emitted on 'http.IncomingMessage' in a node.js http.request. In Node.js, the 'http.IncomingMessage' object is used to represent the incoming HTTP request message. This object is a readable stream, and it can emit various events such as 'data', 'end', and 'error'. One of the events
3 min read
What is the difference between eq() and get() methods in jQuery ?
In this article, we will discuss all the differences between eq() and get() methods in jQuery. eq() Method: This method is used to locate the selected elements directly and returns an element with a specific index. Syntax: $(selector).eq(index) Example: In this example, we will set the different text colors on the 0th and 2nd index paragraphs. C/C+
2 min read
HTTP headers | Access-Control-Allow-Methods
The Access-Control-Allow-Methods header is a Cross-Origin Resource Sharing(CORS) response-type header. It is used to indicate which HTTP methods are permitted while accessing the resources in response to the cross-origin requests. Syntax: Access-Control-Allow-Methods: <method>, <method>, ... OR Access-Control-Allow-Methods: * Directives
1 min read
How to use services with HTTP methods in Angular v17?
In Angular 17, services play an important role in managing HTTP requests to backend servers. By encapsulating HTTP logic within services, you can maintain clean, modular, and testable code. In this article, we'll explore how to use services to handle HTTP requests effectively in Angular 17 applications. Table of Content Services in AngularImplement
3 min read
How to Disable HTTP Methods in Apache?
To prevent the collection of specific system calls that could offer attackers Windows running Apache servers a backdoor, we can Turn off unwanted HTTP methods on the Apache web server. This increases the security of our web application and prevents unwanted attacks. PrerequisitesApache InstalledAdministrative AccessBackup ConfigurationSteps to disa
2 min read
Express JS HTTP Methods
In this article, we are going to learn about the different HTTP methods of Express JS. HTTP methods are hypertext transfer protocol methods to exchange data between two or more layers of an application using a request and response cycle. In web development, we use HTTP methods to connect client-side code to server-side code and databases. The datab
4 min read
5 HTTP Methods in RESTful API Development
JavaScript is by far one of the most popular languages when it comes to web development, powering most websites and web applications. Not being limited to only the client-side JavaScript is also one of the most popular languages which are used for developing server-side applications. Organizations use Javascript to create interactive and dynamic we
12 min read
Two most misunderstood terms GET and POST in web development
If you have done any kind of web development then you must have come across these two terms GET & POST. These terms are introduced with respect to the form tag. The explanation was like this: “In the form tag, there is an attribute called method. There you can specify in which way you want to send data to the backend. There are two values prese
7 min read
Get and Post method using Fetch API
The fetch() method is used to send HTTP requests to the server without refreshing the page, providing an efficient alternative to the older XMLHttpRequest object. One of the main advantages of fetch() is that it uses Promises, which allow for better management of asynchronous operations compared to callbacks. Promises help avoid "callback hell," wh
4 min read
What is the Difference Between PUT, POST, and PATCH in RESTful API?
In the context of RESTful web services, HTTP defines several methods for manipulating resources. The most commonly used methods are POST, PUT, and PATCH. POST The POST method is used to submit an entity to a resource. It is used for creating a new resource or adding a new entity to an existing resource. When a POST request is sent, the server creat
11 min read
What is the difference between export.create and router.post?
export.create and router.post are used in the context of backend frameworks like Express JS. They both are used for handling HTTP requests and operate at different levels within the framework. In this article we will learn about export.create and router.post and see the key differences between them. PrerequisitesNode JSExpress JSPostmanTable of Con
3 min read
How to get form data using POST method in PHP ?
PHP provides a way to read raw POST data of an HTML Form using php:// which is used for accessing PHP’s input and output streams. In this article, we will use the mentioned way in three different ways. We will use php://input, which is a read-only PHP stream. We will create a basic HTML form page where we can use all the possible approaches one at
2 min read
How to send different types of requests (GET, POST, PUT, DELETE) in Postman.
In this article, we are going to learn how can we send different types of requests like GET, POST, PUT, and DELETE in the Postman. Postman is a popular API testing tool that is used to simplify the process of developing and testing APIs (Application Programming Interface). API acts as a bridge between two software applications which enables them to
5 min read
How to get the POST values from serializeArray in PHP ?
When working with forms in web development, it's common to use JavaScript to serialize form data into a format that can be easily sent to the server. One popular method for serializing form data is using jQuery's serializeArray() function. However, once the data is serialized and sent to the server via a POST request, you need to retrieve and proce
2 min read
How to get information sent via post method in PHP ?
In this article, we will learn to get information via the post method in PHP. In PHP, we can use the $_POST method as a superglobal variable that is operated to manage form data. After we click on submit button and the page will send the data through the post method. We can use the data after storing it in a variable according to our requirements.
2 min read
How to Get POST Data in Node ?
Handling POST data is a fundamental aspect of developing web applications and APIs using Node.js. POST requests are used when a client needs to send data to the server, such as submitting form data, uploading files, or sending JSON payloads. This article will cover various methods to retrieve and handle POST data in Node.js, enhancing your server-s
4 min read
Difference between HTTP and IPFS
HyperText Transfer Protocol (HTTP): HTTP is an application layer protocol created by Tim Berners Lee at Cern in 1989, it is currently used for most of the data transfer on the web. It is the foundation of data communication using hypertext files on the World Wide Web. InterPlanetary File System (IPFS): IPFS is a relatively new protocol that can cha
2 min read
three90RightbarBannerImg