[Reprinted] difference between GET and POST in HTTP, getpost
Difference between GET and POST in HTTP
GET and POST are two basic methods of HTTP requests. To tell them the difference, people who have been in contact with WEB development can say either or both.
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 by yourself, or you have read the differences summarized by many authoritative websites. You know exactly when to use them.
When you are asked this question during the interview, your heart is full of confidence and joy.
You can easily give a "standard answer ":
GET is harmless when the browser rolls back, and POST will submit the request again.
The URL generated by GET can be Bookmark, but not POST.
The GET request will be automatically cached by the browser, but the POST will not, unless manually set.
GET requests can only undergo url encoding, while POST supports multiple encoding methods.
The GET request parameters are completely retained in the browser history, while the parameters in POST are not retained.
There are limits on the length of parameters transmitted by GET requests in the URL, and there are no POST parameters.
For the data type of the parameter, GET only accepts ASCII characters, but there is no limit on POST.
GET is less secure than POST because parameters are directly exposed to URLs, so they cannot be used to transmit sensitive information.
The GET parameter is passed through the URL, and the POST is placed in the Request body.
(For the answers to this standard, see w3schools)
"Sorry, this is not our answer !"
Please tell me the truth...
If I tell you that GET and POST are essentially the same, Do you believe them?
Let's take a look at GET and POST!
What is GET and POST? Two request sending methods in HTTP protocol.
What is HTTP? HTTP is a TCP/IP-based protocol for how data can be communicated on the World Wide Web.
The bottom layer of HTTP is TCP/IP. Therefore, the bottom layer of GET and POST is TCP/IP, that is, GET/POST is a TCP link. GET and POST can do the same thing. You need to add the request body to GET and url parameters to POST. Technically, the request body is complete.
So what are the differences in the "standard answer?
In my world of the World Wide Web, TCP is like a car. We use TCP to transport data. It is very reliable and never suffers from missing parts. However, if all the cars on the road look exactly the same, then the world looks like a mess. The cars that send emergency parcels may be blocked by the cars that carry the goods in front of them, the entire transportation system will surely be paralyzed. In order to avoid this situation, the traffic rule HTTP was born. HTTP sets several service categories for vehicle transportation, including GET, POST, PUT, and DELETE. HTTP specifies that when a GET request is executed, the GET label (set method to GET) should be attached to the car, and the transmitted data should be placed on the roof (url) for easy recording. For a POST request, the POST label should be attached to the vehicle and the goods should be placed in the carriage. Of course, you can also secretly store some goods in the carriage when you GET it, but this is not glorious. You can also put some data on the roof during POST, which is silly. HTTP is only a code of conduct, while TCP is the basic implementation of GET and POST.
However, we can only see that HTTP requires the transmission channel (url or requrest body) of the GET and POST parameters. Where does the parameter size limit in the "standard answer" come from?
In my world of the World Wide Web, there is another important role: transportation companies. Different browsers (initiate http requests) and servers (accept http requests) are different transport companies. Theoretically, you can add unlimited heap cargo on the roof (parameters in the url ). However, transportation companies are not stupid. loading and unloading are also costly. They will limit the amount of transportation at a time to control risks. A large amount of data is a huge burden on browsers and servers. The unwritten rule in the industry is that (MOST) browsers usually limit the url length to 2 K bytes, while (MOST) servers process a maximum of 64 K URLs. Otherwise, it will not be processed. If you use the GET service and secretly store data in the request body, the processing methods of different servers are also different. Some servers will help you unload and read the data, while some servers will ignore the data directly, although GET can contain the request body, it cannot be guaranteed to be received.
Now you know that GET and POST are essentially TCP links, and there is no difference. However, HTTP regulations and Browser/Server restrictions make them different in the application process.
What do you think is the end of this article?
Our big BOSS is waiting to appear...
How mysterious is this BOSS? When you try to find the difference between "GET and POST" on the Internet, the search results you will see never mention it. What is he...
There is another major difference between GET and POST, Simply put:
GET generates a TCP packet; POST generates two TCP packets.
Long said:
For GET requests, the browser will send both the http header and data, and the server will respond to 200 (return data );
For POST, the browser first sends the header, the server responds to 100 continue, the browser then sends data, and the server responds to 200 OK (data is returned ).
That is to say, GET only needs to run a car to deliver the goods, while POST has to run two trips. First, say "hi, I am waiting to deliver a batch of goods. You will open the door to greet me. "Then I will send the goods back.
Because POST requires two steps and consumes more time, it seems that GET is more effective than POST. Therefore, the Yahoo team recommends replacing POST with GET to optimize website performance. But this is a pitfall! Exercise caution when jumping in. Why?
1. GET and POST have their own semantics and cannot be mixed at will.
2. According to research, in the case of a good network environment, the time difference between the packet sending time and the time difference between the two packages can basically be ignored. In the case of poor network environment, TCP of the two packets has a great advantage in verifying the integrity of the data packets.
3. Not all browsers send packets twice in POST, and Firefox only sends packets once.
Now, when the interviewer asks you "The difference between GET and POST", is that true?