Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the difference between GET and POST in HTTP

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces you how to understand the difference between GET and POST in HTTP. The content is very detailed. Interested friends can refer to it for reference. I hope it can help you.

GET and POST are two basic methods of HTTP requests, to say their difference, people who have been exposed to WEB development can say one or two.

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 you may have seen the difference summarized by many authoritative websites, and you know exactly when to use what.

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 harmless when the browser rolls back, while POST submits the request again.

URL addresses generated by GET can be bookmarked, while POST cannot.

GET requests are actively cached by browsers, whereas POST is not, unless manually set.

GET requests can only be url encoded, while POST supports multiple encodings.

GET request parameters are kept intact in the browser history, while POST parameters are not kept.

GET requests pass length limits on the parameters in the URL, whereas POST does not.

GET accepts only ASCII characters for parameter data types, while POST has no restrictions.

GET is less secure than POST because parameters are exposed directly on the URL and cannot be used to pass sensitive information.

GET parameters are passed through the URL and POST is placed in the Request body.

"Unfortunately, that's not the answer we wanted! "

Please tell me the truth...

Would you believe me if I told you that GET and POST are essentially the same?

Let's take off the coat of GET and POST and be honest!

What are GET and POST? There are two ways to send requests in HTTP.

What is HTTP? HTTP is a TCP/IP-based protocol for how data is communicated in the World Wide Web.

HTTP is TCP/IP. Therefore, the underlying layer of GET and POST is TCP/IP, that is, GET/POST are TCP links. GET and POST can do the same thing. You have to add the request body to GET and the url parameter to POST, which is technically completely passable.

So, what are the differences in the standard answers?

TCP is like a car in our world of the World Wide Web. We use TCP to transport data. It's reliable. There's never a missing piece. But if the roads were full of identical cars, the world would look chaotic. Cars delivering urgent mail could be blocked by cars loaded with goods ahead, and the entire transportation system would be paralyzed. To prevent this from happening, traffic rules HTTP was born. HTTP sets several service categories for automobile transportation, including GET, POST, PUT, Delete, etc. HTTP specifies that when a GET request is executed, the automobile should be labeled GET (set method to GET), and the transmitted data should be placed on the roof (url) for convenient recording. If it is a POST request, label the vehicle POST and place the cargo in the compartment. Of course, you can also secretly hide some goods in the carriage during GET, but this is very disgraceful; you can also put some data on the roof during POST, which makes people feel stupid. HTTP is just a code of conduct, and TCP is the basis of how GET and POST are implemented.

However, we only see HTTP making demands on the delivery channel (url or requestbody) for GET and POST parameters. Where does the parameter size limitation in Standard Answers come from?

There is another important player in our big world wide web world: transportation companies. Different browsers (originating http requests) and servers (accepting http requests) are different shipping companies. Although theoretically, you can stack cargo on the roof (parameters in url). However, transportation companies are not stupid. Loading and unloading also have a lot of costs. They will limit the amount of single transportation to control risks. Too much data is a great burden on browsers and servers. The unwritten rule in the industry is that (most) browsers typically limit URLs to 2K bytes, while (most) servers handle URLs up to 64K in size. The excess shall not be dealt with. If you use GET service, secretly hide the data in the request body, different servers handle it differently, some servers will help you unload, read the data, some servers ignore it directly, so although GET can carry the request body, it cannot be guaranteed to be received.

OK, now you know that GET and POST are essentially TCP links and there is no difference. However, due to HTTP regulations and browser/server limitations, they reflect some differences in the application process.

Do you think this article is over?

Our big BOSS is still waiting to appear...

How mysterious is this BOSS? When you try to find the difference between GET and POST online, the search results you will see never mention him. What is he...

GET and POST also have a major difference, simply put:

GET generates one TCP packet;POST generates two TCP packets.

The long one said,

For GET requests, the browser sends http header and data together, and the server responds with 200(return data).

For POST, the browser sends the header first, the server responds 100 continue, the browser sends the data, and the server responds 200 ok(return data).

That is to say, GET only needs a car to run once to deliver the goods, while POST has to run twice, *** times, first to say hello to the server,"Hey, I'm going to deliver a batch of goods later, you open the door to meet me," and then go back and deliver the goods.

Because POST takes two steps and consumes a bit more time, GET seems to be more efficient than POST. The Yahoo team recommends replacing POST with GET to optimize website performance. But it's a pit! Jumping in requires caution. Why not?

1. GET and POST have their own semantics and cannot be mixed casually.

2. According to research, in the case of a good network environment, the difference between the time of sending a packet and the time of sending two packets can be ignored. In the case of bad network environment, TCP with two packets has great advantages in verifying packet integrity.

3. Not all browsers send packets twice in POST; Firefox sends them only once.

Now, when the interviewer asks you again,"What's the difference between GET and POST?"

How to understand the difference between GET and POST in HTTP is shared here. I hope the above content can be of some help to everyone and learn more. If you think the article is good, you can share it so that more people can see it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report