Differences between http get and post

Source: Internet
Author: User
Random thoughts, webdev @ 04 May 2010, "10 Comments"

I complained on Twitter that I was not satisfied with the answer to the difference between HTTP Gete and post during the interview. Some people were not clear. At that time, I only replied to rfc2616. Free time

Most of the answers received during the interview are: Post is secure, because the submitted data is not visible or encrypted, and other Chinese characters are garbled during get (in the address bar ), maximum Data Length.

It is certainly wrong to say that post is safer than get. Post and get are transmitted in plain text, and can be observed using plug-ins such as httpfox or similar tools such as Wireshark.

There is a big difference between post and get. In terms of semantics, get is used to obtain resources on a specified URL and read operations. The important thing is that no matter how many times a resource is get, its status will not change, in this sense, get is secure (not encrypted or data-protected ). Because get is safe, the content returned by get can be cached by the browser and Cache Server (there are still many details, but this does not affect the discussion here ).

The meaning of post is to "append/Add" data to the specified resource, so it is insecure, the involved code will think that this operation will modify the status of the object resource, so the browser will jump out of the confirmation box when you press F5, And the cache server will not cache the POST request returned content.

Unfortunately, no applicants have been able to mention this so far. I guess there are probably two reasons behind this. One is that most people (and I am the same) are satisfied that they only need to complete the task. No matter which one is used, the form is submitted and the data is processed, when the content is displayed or redirected to another page, even if a task is completed, it is crossed out from the task table and ended. In addition, it seems that most projects (OA, CRM, and MIS) can be used in most cases.

At the same time, after the WS-* concepts advertised by commercial organizations in the media and books and the "convenient" code generation tools provided by the integrated development environment are used, "Understand" that all web service calls use post, and subconsciously confirm that post and get are the same, and get can do the same, post can do it, post is just get ++. Naturally, post can be used with post, so you don't have to care about the difference between the two.

This reminds me of a concept recently learned: radius of comprehension, radius of understanding:

When learning concept A, you must first understand concept B, and concept C is the prerequisite for understanding concept B. When B and C are both new concepts to be learned, we can say that the radius of a's understanding is 2 ,:

A --> B --> C|--1--|--2--|

When learning about web development and getting started with get and post, the "radius of understanding" may include:

Post vs. GET | ---> conditional get-> etag-> cache | '--> Status Code' ---> HTTP Method --> URL

It is often because we are only satisfied with the tasks we have been asked to complete, or are too lazy to ask why, so we can set our understanding radius to zero, so we cannot learn more deeply, therefore, we only know the difference between post and get, instead of knowing where the difference is, what is conditional get and cache header.

Speaking of this from a simple interview question, it seems like you have made a huge fuss.

<Update>
I saw fenng buzz in this article, which caused some comments. Therefore, I will discuss two concepts here: Safe and idempotent (idempotent ).

Security means that there is no obvious side effect on the user (including modifying the resource status ). Get and head in the HTTP method are safe.

Idempotent means that a method returns the same result no matter how many operations it performs. Put (put the content to the specified URL), delete (delete resources represented by a URL), although all of them have modified the resource content, the results are the same for multiple operations, so it is similar to head, get is idempotent.

Therefore, according to the HTTP protocol, get is secure and idempotent, while post is neither secure nor idempotent.
</Update>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.