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

What are the differences between the two basic request methods GET and POST

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

Share

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

This article focuses on "what are the differences between the two basic request methods of GET and POST". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are the differences between the two basic request methods of GET and POST?"

The most intuitive difference is that GET includes parameters in URL, and POST passes parameters through request body.

You may have written countless GET and POST requests yourself, or you've seen the differences summed up by many authoritative websites, and you know exactly when to use them.

When you are asked this question in the interview, your heart is full of confidence and joy.

You easily come up with a "standard answer":

GET is harmless when the browser rollback, and POST submits the request again.

The URL address generated by GET can be Bookmark, but POST cannot.

The GET request will be actively cache by the browser, while the POST will not, unless set manually.

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

The GET request parameters will be fully preserved in the browser history, while the parameters in POST will not be retained.

The parameters passed by the GET request in the URL are limited in length, while the post does not.

For the data type of the parameter, GET accepts only ASCII characters, while POST has no restrictions.

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

The GET parameter is passed through URL, and the POST is placed in Request body.

"Unfortunately, this is not the answer we want!"

Please tell me the truth.

Would you believe me if I told you that there is essentially no difference between GET and POST?

Let's take off the cloak of GET and POST and be honest with each other.

What are GET and POST? In the HTTP protocol, there are two ways to send requests.

What is HTTP? HTTP is a protocol based on TCP/IP about how data communicates on the World wide Web.

The underlying layer of HTTP is TCP/IP. So the underlying layer of GET and POST is also TCP/IP, that is, GET/POST is a TCP link. GET and POST can do the same thing. You have to add request body to GET and url parameter to POST, which is technically feasible.

So, what about 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 loses a few pieces.

But if the road is full of cars that look exactly the same, the world looks like a mess. Cars delivering dispatches may be blocked by cars full of goods in front of them, and the whole transportation system will surely be paralyzed. In order to prevent this from happening, the traffic rule HTTP was born.

HTTP sets several service categories for motor transportation, such as GET, POST, PUT, DELETE, etc. HTTP stipulates that when executing a GET request, the car should be labeled as GET (set method to GET), and the transmitted data should be placed on the roof (url) to facilitate recording.

If it is requested by POST, label the car with the POST label and put the goods in the car. Of course, you can also secretly hide some goods in the car during GET, but this is very dishonorable; 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 of how GET and POST are implemented.

However, we can only see that HTTP requires the transmission channel (url or requrest body) of GET and POST parameters. Where do the restrictions on parameter size in the Standard answer come from?

In my 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 shipping companies. In theory, though, you can pile goods indefinitely on the roof of the car (with unlimited parameters in url).

But shipping companies are not stupid, loading and unloading also have high costs, they will limit the volume of single transport to control the risk, too much data is a great burden on browsers and servers. Industry

The unwritten rule is that (most) browsers usually limit the length of url to 2K bytes, while (most) servers handle a maximum of 64K url. The excess will not be dealt with.

If you use GET service to hide data secretly in request body, different servers will handle it differently. Some servers will help you unload and read the data, while others will ignore it directly. So, although GET can carry request body, there is no guarantee that it will be received.

Well, now you know, GET and POST are essentially TCP links, and there's no difference. However, due to the rules of HTTP and browser / server restrictions, they reflect some differences in the application process.

You think this article is over?

Our big BOSS is still waiting to come out.

How mysterious is this BOSS? When you try to find "the difference between GET and POST" on the Internet, he is never mentioned in the search results you will see. What on earth is he?

There is another major difference between GET and POST:

To put it simply: GET generates one TCP packet; POST generates two TCP packets.

Long said: for the GET request, the browser will send out both http header and data, and the server will respond to 200 (return data)

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

In other words, GET only needs a car trip to deliver the goods, while POST has to make two trips, the first one, to say to the server, "Hey, I'm going to deliver a shipment later, you open the door to meet me", and then deliver it back.

Because POST takes two steps and takes a little more time, it seems that GET is more effective than POST. Therefore, the Yahoo team recommends replacing POST with GET to optimize the performance of the website.

But this is a pit! You need to be careful when jumping in. Why?

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

two。 According to the research, when the network environment is good, the difference between the time of sending one packet and the time of sending two packets can be ignored. In the case of poor network environment, the TCP of two packets has great advantages in verifying packet integrity.

3. Not all browsers send packets twice in POST, but only once in Firefox.

Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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