The difference between post and get in an HTTP request

Source: Internet
Author: User

first, the principle of difference

In general, we enter a URL in the browser to access the site is a GET request, in the form form, you can specify by setting method is a Get or post submission method, the default is get Submit method.

HTTP defines different ways to interact with the server, the most basic of which are: Get,post,put,delete,head, where get and head are called security methods because HTTP requests using GET and head do not produce any action. Not generating an action means that the get and head HTTP requests do not produce any results on the server. But security is not an action, and the security method here simply means that the information is not modified.

According to the HTTP specification,Post may modify requests for resources on the server . For example, CSDN's blog, a user submits an article or a reader submits a comment is done through a POST request, because the submission of the article or comments after the submission of resources (that is, a page) is different, or that the resources have been modified, these are "unsafe methods."

ii. The difference of manifestation form

<method> <request-URL> <version>

<entity-body>

In an HTTP request, the singular line must be a request line, including the request method, the request URL, and the HTTP version information used for the message. It is followed by a herders section, which can have 0 or a header that describes the additional information that the server will use. After the first is a blank line, and finally the body of the message entity, including a data block of arbitrary data. But not all messages contain the body part of the entity.

Get Request instance:

GET http://weibo.com/signup/signup.php?invitecode=2388493434

Host:weibo.com

accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8

Post Request instance:

post/inventory-check.cgi http/1.1

  Host:www.joes-hardware.com

content-Type: text/plain

  content-Length:

  Item=bandsaw 2647

Let's take a look at the differences between the two request types:

1.post more secure (not as part of a URL, not cached, stored in server logs, and browser browsing history)
2.post sends a larger amount of data (in the HTTP specification, there is no limit on the length of the URL and the size of the data being transmitted.) However, in the actual development process, for get, the specific browser and server to the length of the URL is limited. Generally not more than 4KB. Therefore, when you use a GET request, the transfer data is limited by the URL length. In the case of post, it is theoretically not restricted because it is not a URL, but in fact each server specifies that the size of the post submission data is limited, and that Apache and IIS have their own configuration. Tomcat is capped at 2M)

3.post can send more data types (get can send only ASCII characters)
4.post is slower than get, get produces a TCP packet, and post generates two TCP packets.
5.get is idempotent, While post is not idempotent (a power-like operation is characterized by the effect of any number of executions is the same as the effect of one execution, get is a security method, the server-side information is not modified, and post modifies the server-side resources)
6.get can be cached, post cannot be cached


Ps:get is faster than post, because the Get and POST request process is different, but the first three steps are the same, with the three-time handshake from the server:
1. The browser requests a TCP connection (first handshake)
2. The server agrees to make a TCP connection (second handshake)
3. The browser confirms and sends the request header and data
4, the server response, the GET request generated a TCP packet, and the POST request generated two TCP packets. Because the GET request data is small, the browser sends the head and data together, the server responds with a OK, and returns the data. And for the POST request, the browser sends the head first, the server responds to the continue, the browser sends data, the server responds with a.

The difference between post and get in an HTTP request

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.