Home  >  Article  >  Backend Development  >  The difference between the two parameters passed by get post

The difference between the two parameters passed by get post

hzc
hzcOriginal
2020-06-12 16:56:277637browse

The difference between the two parameters passed by get post

get post The difference between the two parameters:

GET and POST are the two basic methods of HTTP requests. Let’s talk about their differences. , Anyone who has been exposed to WEB development can tell you something.

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.


The difference between the two parameters passed by get post

You easily gave a "standard answer":

GET is harmless when the browser rolls back. 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.

There is a length limit on the parameters transmitted in the URL for the GET request, but there is no length limit 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!"

The difference between the two parameters passed by get post

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!

The difference between the two parameters passed by get post

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"?

The difference between the two parameters passed by get post

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 GET tag (set the method to GET), and the transmitted data is required to be placed on the roof (in the URL) to facilitate 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?

The difference between the two parameters passed by get post

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 theoretically, 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, data is secretly hidden 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 With request

body, there is no guarantee that it will 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?

The difference between the two parameters passed by get post

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 requests, the browser will send the http header and data together, and the server will respond with 200 (return data);

For POST, the browser will first Send 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, "Hey, I'm going to 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 difference between the two parameters passed by get post

Finish! ! !

Recommended tutorial: "php tutorial"

The above is the detailed content of The difference between the two parameters passed by get post. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn