preface
After I posted an html2Canvas is always cross-domain, one step in one step, a byte big guy reminded me why the base64 image I generated will open directly in the browser address bar, there will be a blank at the bottom of the problem, it was like a double take.
What happens to the address entered in the address bar?
I won’t tell you about the rendering process of HTML. I will write a post next time to share it with you. There must be a request, and we’ll find a GET request.
GET and POST are two of the most frequently used methods in front and back end interactions. Sometimes you may find an OPTION (this is called pre-request, which is used to handle cross-domain requests.
Today we’re going to take a look at the differences between GET and POST.
The same
How many people would disagree if I said GET and POST are essentially the same thing?
GET and POST are only two request methods specified by THE HTTP protocol for different tasks.
What is HTTP? HTTP is a TCP/ IP-based protocol for how data is communicated on the World Wide Web.
The underlying layer of HTTP is TCP/IP. So the underlying layer of GET and POST is ALSO TCP/IP, which means that both GET and POST are TCP links. So they’re essentially the same.
GET and POST are distinguished by HTTP rules and browser/server restrictions that make them different in application.
The request process looks something like this:
- The client IP address sends the request.
- The sent request packet is transmitted to the remote server IP address over the NETWORK through TCP.
- The server IP receives the request packet, parses and processes the request packet and then sends the result back to the client via TCP.
- The user can then view the desired response data.
The mark
While the essence of GET and POST requests is the same — both are TCP connections — there are some differences in how they are used.
The differences we are talking about here are actually established things, and the boundaries of some differences may not be very clear.
Effect of different
Since the two methods are produced for different division of labor, their functions must be different:
- GET is used to obtain resources from the server
- POST is used to submit resources to the server
In fact, this is a nonsense, the reason for listing, is to content more comprehensive some.
Parameters are passed in different ways
This is probably the most intuitive thing we can see.
- The parameter to GET is usually passed
?
Following the URL, multiple parameters pass&
Connection, thanhttps://api.uomg.com/api/rand.img2?sort=%E7%BE%8E%E5%A5%B3&format=json
. - The parameters for POST are generally included in the
request body
In the
The distinction is not absolute. GET can also carry parameters through params, and POST urls can also carry parameters after them, though this is generally not recommended. Once, I was confused to add parameters after POST to request, the backend side has been unable to find the reason
Different security
The security of GET and POST is different because of the way parameters are passed: GET is less secure than POST because parameters are directly exposed to the URL, so GET cannot be used to pass sensitive information.
From the point of view of transmission, they are not secure, because HTTP is transmitted in plaintext over the network, as long as the network node to capture the packet, the complete data packet, to secure transmission, only encryption, namely HTTPS.
Parameter length limits vary
GET and POST pass parameters have different lengths:
- The amount of data transmitted by get is small and cannot be larger than 2KB.
- Post transfers a large amount of data and is generally considered unrestricted by default.
Let’s be clear here: HTTP has no Body or URL length restrictions. Most of the restrictions are browser and server reasons.
Server because processing long URL to consume more resources, for performance and security (to prevent malicious construction of long URL to attack) consideration, will give THE URL length limit.
Parameter data types are different
The data type of the argument, GET accepts only ASCII characters, and POST has no limit.
Different encoding methods
GET requests can only be URL coded (Application/X-www-form-urlencoded)
POST supports many encoding methods (Application/X-www-form-urlencoded or multipart/form-data). Use multiple encodings for binary data.
Different caching mechanisms
This needs to be explained from the following points:
- GET requests are actively cached by browsers, whereas POST requests are not, unless set manually.
- GET request parameters are retained in browser history, while parameters in POST are not.
- The URL generated by GET can be bookmarked, but not by POST.
- GET is harmless when the browser falls back, while POST resubmits the request.
Different time consumption
The differences between GET and POST request times are mainly due to:
- GET generates a TCP packet;
- POST generates two TCP packets.
For GET requests, the browser sends both the header and the data, and the server responds with 200 (return data). For POST, the browser sends a Header, the server responds with 100 continue, the browser sends data, and the server responds with 200 OK.
Different request process
POST request process:
- Browser requests A TCP connection (first handshake)
- Server allows TCP connection (second handshake)
- The browser acknowledges the request and sends a POST header (the third handshake is a small packet, so HTTP sends the first data at this point).
- The server returns a 100 Continue response
- Browser sends data
- The server returns a 200 OK response
The process of a GET request:
- Browser requests A TCP connection (first handshake)
- Server allows TCP connection (second handshake)
- The browser acknowledges the request and sends the GET header and data (the third handshake is a small packet, so HTTP sends the first data at this point).
- The server returns a 200 OK response
In a good network environment, the time difference between sending a packet once and sending a packet twice can be ignored. In the case of poor network environment, the TCP of two packets has great advantages in verifying the integrity of packets.
conclusion
The similarities and differences between GET and POST are summarized so much, most of the content is scraped, mainly their own also want to summarize, stand on the shoulders of giants for reference
Get requests have a size limit of 2KB or less. If they are larger than 2KB, the browser automatically filters them out. Still want to thank big guy’s guidance, let me review again
expand
HTTP: GET/POST