The difference between get and post in the HTTP request method (detailed description)

Source: Internet
Author: User

HTTP protocol is widely used in modern network communication, there are 7 kinds of requests in HTTP version 1.0, there are 8 kinds of requests in HTTP 1.1, and the most commonly used in these requests is get and post, there are many articles about the difference between get and POST request. But they are not comprehensive enough. Let us now elaborate on the differences between the two approaches.

(a) from the HTTP message view

The GET Request method places the request information behind the URL, requesting information and the URL between the. Separated, the request information is formatted as a key-value pair, such as Https://baike.baidu.com/item/Python/407313?fr=aladdin, which exposes the request information directly to the URL and is less secure. Also from the message structure, because the request information is placed in the URL, so the request message does not need to report style.

The Post request method puts the request information in the newspaper style, obtains the request information must parse the message, therefore the security is higher than gets the method to be more high (actually obtains the request information in the newspaper style is also very easy, therefore the security does not have too many differences, specifically to solve the transmission of security problems also rely on HTTPS), in addition to the request message contains newspaper style.

Because the request information in get is placed in the URL, there is a length limitation because the URL itself is limited in length. The request information in post is placed in the newspaper style, so there is no limit to the length of the data.

(ii) from the database level

Cet request method conforms to idempotent and security, (idempotent definition: One operation of the database and the results obtained by multiple operations are consistent, it is considered to be idempotent.) The definition of security: the operation of the database does not change the data in the database, it is considered to be security, the GET request is a query operation, so it does not change the data in the database, it is considered to be in compliance with security. The fact that a GET request may result in multiple requests (such as a change in the data in the database in the middle of a two request) is a non-idempotent definition, but because the GET request knowledge queries the database, it does not make any changes to the database and is considered idempotent.

The Post request method is neither idempotent nor secure, first the Post request method submits data to the database, and therefore changes the data in the database. Second, the POST request is likely to get different results each time, because the POST request is at the top-level URL, and each request adds a new resource (which is the biggest difference between the post and put, the Put method is idempotent).

  Note: The security mentioned here and the security mentioned in the previous section are not the same concept, do not confuse.

(iii) from other perspectives

Get requests can be cached.

The GET request is saved in the browser's browsing history.

URLs with GET requests can be saved as browser bookmarks.

And the Post method does not have the above function. Caching is also widely used for get requests, and the number of requests per day on modern networks is huge, and most of them are read-only requests, which is a huge waste of resources if all of these requests are left to the WEB server for direct processing. From the second part know that get expression is a idempotent, secure, it should not produce other side effects in addition to return results, so most get requests (usually more than 90%) are directly cached by the CDN, which can greatly reduce the burden on the WEB server. The post is non-idempotent and has side effects, so it must be handled by the WEB server.

The difference between get and post in the HTTP request method (detailed description)

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.