Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • PHP Tutorial
  • PHP Exercises
  • PHP Array
  • PHP String
  • PHP Calendar
  • PHP Filesystem
  • PHP Math
  • PHP Programs
  • PHP Array Programs
  • PHP String Programs
  • PHP Interview Questions
  • PHP GMP
  • PHP IntlChar
  • PHP Image Processing
  • PHP DsSet
  • PHP DsMap
  • PHP Formatter
  • Web Technology
Open In App
Next Article:
Difference between MQTT and HTTP protocols
Next article icon

Difference between HTTP GET and POST Methods

Last Updated : 16 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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.

Table of Content

  • HTTP GET
  • HTTP POST
  • Difference between HTTP GET and HTTP POST

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

Next Article
Difference between MQTT and HTTP protocols

G

gauravgandal
Improve
Article Tags :
  • Difference Between
  • Web Technologies
  • PHP
  • Web technologies
  • HTTP
  • PHP-Questions
  • php

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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences