reference

Juejin. Cn/post / 684490…

zhuanlan.zhihu.com/p/25028045

Juejin. Cn/post / 685457…

background

In the past, I was always asked about the difference between Post and Get requests. Because I didn’t look deeply, I just answered some superficial phenomena and was always ridiculed. For example, Post is more secure than Get. Get is used to pull data and Post is used to submit data.

Post

  • A POST request places the data in the body of the HTTP request package and is not directly exposed to the user.
  • POST requests are theoretically unlimited in size, but in practice each server regulates the size of the data submitted by POST.
  • POST is more secure than Get because the parameter is not stored in browser vertical or Web server logs.
  • POST generates two TCP packets, the header is sent first, the server responds with 100ms and then continues, sending data, server 200 and then returns data.
  • POST Indicates that the browser rolls back the request again.

Get

  • The data for the GET request is appended to the URL, separated with a question mark, and multiple parameters are concatenated with &.
  • The data for the GET request is exposed in the address bar.
  • GET request urls are encoded in ASCII rather than Unicode.
  • The transfer size of GET requests is limited to 2KB.
  • GET is insecure and will be actively cached by the browser.
  • GET generates a TCP packet, and head and data are sent together.
  • GET Browser rollback is harmless.

There is another important difference between GET and POST. Simply put, GET produces a TCP packet; POST generates two TCP packets. Because POST takes two steps and consumes a little more time, it looks like GET is more efficient than POST. But… It’s not a panacea.

GET and POST have their own semantics and cannot be used together.

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.

Not all browsers send packages twice in POST, Firefox only sends them once.