Difference between HTTP GET and POST Methods
Last Updated : 16 Sep, 2024
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 data | Data 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 |
Similar Reads
Difference between http:// and https://
When browsing the web, you might have noticed URLs starting with http. It is either âhttp://â or âhttps://â. Such prefixes show how data is transmitted between your browser and the website that you are accessing. HTTP and HTTPS are both protocols for communication but they are different in several w
7 min read
Difference Between HTTP and HTTPS
HTTPS is just HTTP with encryption. The primary distinction between these two names is that HTTPS is more secure than HTTP since it uses TLS (SSL) encryption for all HTTP requests and answers, even the standard ones. In this article, we are going to discuss what is HTTP and HTTPS and their advantage
6 min read
Difference between MQTT and HTTP protocols
1. Message Queuing Telemetry Transport (MQTT) : It was created by Andy Standford-Clark and Arlen Nipper. It is an IoT interaction protocol based on the Publish/Subscribe model. This model is a simple model that provides support for QoS (Quality of Service). Due to its abilities, it can be found in e
2 min read
Difference between SOAP and HTTP
Simple Object Access Protocol (SOAP) is a network protocol for exchanging structured data between nodes. It uses XML format to transfer messages. It works on top of application layer protocols like HTML and SMTP for notations and transmission. SOAP allows processes to communicate throughout platform
9 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 (IPF
2 min read
Difference between HTML and HTTP
HTML stands for HyperText Markup Language and is one of the basic tools any webmaster or web designer uses while HTTP stands for HyperText Transfer Protocol and is a tool used in browsing the web. It would be helpful for anyone designing web sources to clearly understand the relation between HTML an
5 min read
Difference between AMQP and HTTP Protocols
AMQP (Advanced Message Queuing Protocol) and HTTP (Hypertext Transfer Protocol) are two communication protocols used in distributed systems, however, they perform different functions and have different properties. In this article, we are going to discuss the differences between AMQP and HTTP protoco
4 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 1
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 te
2 min read
Difference Between PUT and PATCH Request
HTTP PUT request is used to replace and update the entire resource or document, while the PATCH request only updates the specific parts of that document. When working with APIs, figuring out the right way to update resources can be tricky. Both PUT and PATCH requests are used for this purpose. This
6 min read