Computer Network - talk about the difference in HTTP GET and POST

I. Introduction

  Today, some research HTTPprotocol, the GETmethod and POSTthe difference method. A study found, GETand POSTtotally not like me to learn Webto understand the development is so, their relationship completely changed my previous understanding. This blog I came to talk about two levels GETwith POSTa difference - the browser level and message level.


Second, the text

  The difference between the level of 2.1 browser

  GETAnd POSTthe difference method in the browser level most people more or less know something, it mainly includes the following aspects:

  Through the above distinction, we summarized in the following two points:

  • The GET : It is used to request to server resources, so there is no side effects, and it is idempotent, can be cached;
  • The POST : used to modify the data request to the server, so there are side effects, it is non-idempotent, it can not be cached;

HTTPIdempotent: Each request will produce the same side effects.

GETIs idempotent, because it is only requested resources, it will not have an impact on the server, that is, no side effects, it is idempotent; and POSTrequests are not idempotent, because it modifies the data, each request will cause side effects again.

  These differences listed above, some are actually causally related, such as POSTto modify the data request to the server, so every time POSTa request to modify the data will, in theory, to the server, and as such, only these few:

  1. Need to re-submit data refresh to get the latest resources;
  2. Non-cacheable, because the POSTrequest will modify the resources, so the old cache resources does not make sense;

  The browser will GETrequest the data into URL, whereas POSTthe requested data into the bodymiddle, so only a few below:

  1. POSTRequest more secure because GETthe request data directly into the URL, the user can see directly, but POSTthe data into bodythe user can not directly visible;
  2. GETOnly the requested data ASCIIcharacter, because the data URLin URLonly allows ASCII characters, and POSTdata into body, the bodyallowed binary data;

  However, these differences are browsers and Webservers to follow HTTP, not the implementation of the agreement GETand POSTthe essential difference between, let's analyze the packet level GETand POSTdifferent.


  2.2 packet-level difference

  Here I give a direct conclusion: GET and POST method is essentially not much different, only packets of different formats as well as the method name . Whether GETa method or POSTmessage method, is HTTPthe message, and HTTPis based on TCP/IPdoing data transmission, that is, at the transport layer, packet transmission of the two methods is not any difference. In the agreement, the GETdata is placed in the method URL, and POSTpacket data is placed bodyis the difference in format, but this is not absolute.


  2.3 depth understanding of the difference between them

  Below I will explain the nature of the above mentioned level to make a difference in interpretation:

(1) GET method is used to request resources from the server, and the POST method request to modify the data server

  This is the HTTPnorm in these two methods convention, but merely agreed, not mandatory. In other words, we can through the GETmethod of requesting a server to modify data, and by POSTrequest to the server resource method. For many Webbeginners developed, we should have done similar things, such as making use Servletor SpringMVCdo Webdevelop, mix GETwith POST. So, for this one difference, it is not certain.

(2) GET method data is placed URL, rather POST into body

  This is also the HTTPnorm these two methods convention message, and the browser when you create the request message is implemented in accordance with this convention, nothing more. That is to say, for the GETrequest, we can also put data bodyin, and for POSTthe data, we can put URLin. We violation of this agreement, the message can still normal transmission, as long as the implementation supports server, you can normally get the data.

Data (3) GET method with a transmission limit (length and type), whereas no POST

  As we have said, GETthe method can only send ASCIIcharacter data, and the length of the data is limited, but POSTyou can send binary data, and there is no length limit. First, the data type, it is not a GETmethod of transmitting only ASCIIcharacter data, but URLcan only into character data, and the GETdata is placed in the method URL, naturally only be URLlimited. If we in the GETmessage bodyplaced data, still able to put binary data. Come talk about the length of the data, HTTPthe specification does not limit URLthe length of the true limit URLthe length of the browser, the browser in order to facilitate the processing of data, as well as security considerations, on the URLlength of the limit. However, the HTTPspecification does not limit the URLlength, we can by way of writing code to create a very, very long containing URLthe HTTPmessage is normally transmitted.

(4) POST method is more secure than the GET method

  The basis for this argument is that the browser does not put POSTthe data into URLthe user can not directly see, it is considered POSTmore secure. However, the process of data transmission, GETand POSTtransmission of packets is no difference, is through the TCPtransmission connection. As long as we pass the packet capture software to crawl the HTTPmessage, in fact, they carry the data are directly visible, there is no security at all. So, strictly speaking, GETand POSTthe security is not much difference. If you want security, you should use HTTPS.

(5) POST request sends two TCP packets

  Internet is also circulating Another difference between them, that the browser will POSTrequest headerand bodyseparately transmitted, generating two TCPsegments, the first transmission header, the server receives the response status code 100after the re-transmission bodyportion. However, the HTTPspecification does not clearly illustrate this point, but also in the actual test, this did not happen. It is considered that this is only self-realization in some browsers, not POSTnecessarily behavior.


Third, the summary

  We're talking about GETand POSTwhen the difference should be as above, Points of discussion. In the browser level, there are many differences between them, some are HTTPstandard convention, but it is still self-realization and most browsers; and In essence, there is not much difference between the two kinds.


Fourth, the reference

Guess you like

Origin www.cnblogs.com/tuyang1129/p/12570894.html