What is the difference between GET and POST in HTTP?
The difference between GET and POST in HTTP
GET and POST are the two basic methods of HTTP requests. Anyone who has been exposed to WEB development can tell their difference.
The most intuitive difference is that GET includes parameters in the URL, and POST passes parameters through the request body.
You may have written countless GET and POST requests yourself, or have read many authoritative websites summarizing their differences. You know very clearly when to use which one.
When you are asked this question in an interview, your heart is filled with confidence and joy.
You easily gave a "standard answer":
GET is invalid when the browser returns Harmful, and POST will submit the request again.
The URL address generated by GET can be Bookmarked, but POST cannot.
GET requests will be actively cached by the browser, but POST will not unless manually set.
GET requests can only be URL encoded, while POST supports multiple encoding methods.
GET request parameters will be completely retained in the browser history, while parameters in POST will not be retained.
The parameters transmitted in the URL for the GET request have length limits, but there are no length limits for POST.
Regarding the data type of parameters, GET only accepts ASCII characters, while POST has no restrictions.
GET is less secure than POST because the parameters are directly exposed on the URL, so it cannot be used to pass sensitive information.
GET parameters are passed through the URL, and POST is placed in the Request body.
(This standard answer is referenced from w3schools)
"Unfortunately, this is not the answer we want!"
Please tell me the truth. . .
If I told you that there is essentially no difference between GET and POST, would you believe it?
Let us take off the cloak of GET and POST and be honest with each other!
What are GET and POST? Two methods of sending requests in the HTTP protocol.
What is HTTP? HTTP is a protocol based on TCP/IP about how data is communicated on the World Wide Web.
The bottom layer of HTTP is TCP/IP. So the bottom layer of GET and POST is also TCP/IP, that is to say, GET/POST are both TCP links. GET and POST can do the same thing. You need to add request body to GET and url parameters to POST. Technically, it is completely feasible.
So, what are the differences in the "standard answer"?
In our world of the World Wide Web, TCP is like a car. We use TCP to transport data. It is very reliable and there will never be any missing items. But if all the cars on the road look exactly the same, the world will look like a mess. Cars delivering urgent messages may be blocked by cars laden with goods in front of them, and the entire transportation system will definitely be paralyzed. To prevent this from happening, Traffic Rules HTTP was born. HTTP has set several service categories for car transportation, including GET, POST, PUT, DELETE, etc. HTTP stipulates that when executing a GET request, the car must be labeled with a GET (set the method to GET), and require Put the transmitted data on the roof of the car (in the url) for easy recording. If it is a POST request, a POST label must be attached to the car and the goods must be placed in the carriage. Of course, you can also secretly hide some goods in the car during GET, but this is very disgraceful; you can also put some data on the roof during POST, which makes people feel silly. HTTP is just a code of conduct, and TCP is the basis for how GET and POST are implemented.
However, we only see that HTTP imposes requirements on the transmission channel of GET and POST parameters (url or request body). Where does the limit on parameter size in the "standard answer" come from?
In our world of the World Wide Web, there is another important role: transportation companies. Different browsers (initiating http requests) and servers (accepting http requests) are different transportation companies. Although in theory, you can pile unlimited goods on the roof of the car (unlimited parameters can be added to the URL). But transportation companies are not stupid. Loading and unloading are also very costly. They will limit the volume of a single shipment to control risks. Too much data will put a great burden on the browser and server. The unwritten rule in the industry is that (most) browsers usually limit URL length to 2K bytes, and (most) servers can handle URLs up to 64K in size. Any excess will not be processed. If you use the GET service and secretly hide data in the request body, different servers handle it differently. Some servers will help you unload and read the data, while some servers ignore it directly. Therefore, although GET can bring the request body, it cannot Guaranteed to be received.
Okay, now you know that GET and POST are essentially TCP links, there is no difference. However, due to HTTP regulations and browser/server limitations, they show some differences in the application process.
Do you think this article ends like this?
Our big BOSS is still waiting to appear. . .
How mysterious is this BOSS? When you try to find "the difference between GET and POST" on the Internet, it is never mentioned in the search results you will see. What exactly is he? . .
There is another major difference between GET and POST. Simply put:
GET generates one TCP data packet; POST generates two TCP data packets.
Long story:
For GET request, the browser will send the http header and data together, and the server will respond with 200 (returning data);
For POST, the browser first sends the header, the server responds with 100 continue, the browser then sends data, and the server responds with 200 ok (return data).
In other words, GET only requires one trip by car to deliver the goods, while POST requires two trips. On the first trip, go and say hello to the server "Hi, I'll deliver one later." When the goods arrive, you open the door to greet me," and then go back to deliver the goods.
Because POST requires two steps and takes a little more time, it seems that GET is more efficient than POST. Therefore, the Yahoo team recommends replacing POST with GET to optimize website performance. But this is a trap! Jump in with caution. Why?
1. GET and POST have their own semantics and cannot be mixed casually.
2. According to research, when the network environment is good, the difference between the time of sending one packet and the time of sending two packets can basically be ignored. When the network environment is poor, TCP with two packets has a great advantage in verifying the integrity of the data packet.
3. Not all browsers will send the packet twice in POST, Firefox only sends it once.
Now, when the interviewer asks you "the difference between GET and POST", is this what you feel in your heart?
The above is the detailed content of What is the difference between GET and POST in HTTP?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

C language functions are the basis for code modularization and program building. They consist of declarations (function headers) and definitions (function bodies). C language uses values to pass parameters by default, but external variables can also be modified using address pass. Functions can have or have no return value, and the return value type must be consistent with the declaration. Function naming should be clear and easy to understand, using camel or underscore nomenclature. Follow the single responsibility principle and keep the function simplicity to improve maintainability and readability.

Export password-protected PDF in Photoshop: Open the image file. Click "File"> "Export"> "Export as PDF". Set the "Security" option and enter the same password twice. Click "Export" to generate a PDF file.

C language functions are reusable code blocks. They receive input, perform operations, and return results, which modularly improves reusability and reduces complexity. The internal mechanism of the function includes parameter passing, function execution, and return values. The entire process involves optimization such as function inline. A good function is written following the principle of single responsibility, small number of parameters, naming specifications, and error handling. Pointers combined with functions can achieve more powerful functions, such as modifying external variable values. Function pointers pass functions as parameters or store addresses, and are used to implement dynamic calls to functions. Understanding function features and techniques is the key to writing efficient, maintainable, and easy to understand C programs.

H5. The main difference between mini programs and APP is: technical architecture: H5 is based on web technology, and mini programs and APP are independent applications. Experience and functions: H5 is light and easy to use, with limited functions; mini programs are lightweight and have good interactiveness; APPs are powerful and have smooth experience. Compatibility: H5 is cross-platform compatible, applets and APPs are restricted by the platform. Development cost: H5 has low development cost, medium mini programs, and highest APP. Applicable scenarios: H5 is suitable for information display, applets are suitable for lightweight applications, and APPs are suitable for complex functions.

The necessity of registering VueRouter in the index.js file under the router folder When developing Vue applications, you often encounter problems with routing configuration. Special...

Although C and C# have similarities, they are completely different: C is a process-oriented, manual memory management, and platform-dependent language used for system programming; C# is an object-oriented, garbage collection, and platform-independent language used for desktop, web application and game development.

Detailed explanation of XPath search method under DOM nodes In JavaScript, we often need to find specific nodes from the DOM tree based on XPath expressions. If you need to...

There are differences in the promotion methods of H5 and mini programs: platform dependence: H5 depends on the browser, and mini programs rely on specific platforms (such as WeChat). User experience: The H5 experience is poor, and the mini program provides a smooth experience similar to native applications. Communication method: H5 is spread through links, and mini programs are shared or searched through the platform. H5 promotion methods: social sharing, email marketing, QR code, SEO, paid advertising. Mini program promotion methods: platform promotion, social sharing, offline promotion, ASO, cooperation with other platforms.
