网上对与HTTP的Method,GET和POST的区别,说得毕竟详细。然后提到一点,说浏览器对两者的还有一个比较容易让人忽略的区别就是:POST会分2次发送,而GET只1次。
GET发送1次,这个没什么好说的。然后对于POST,做了个测试,结果如下:
IE11浏览器【11.0】,分2次发送
Opera浏览器【49.0.2725.47】,分1次发送
Chrome浏览器【64.0.3282.119(正式版本) (64 位)】,分2次发送
Firefox【57.0.4 (64 位)】,1次发送
Safari【5.1.7】,2次发送
有的文章说,POST要请求2次,其实这应该是不准确的说法,请求依然是1次,只是分别发送了请求Header和Body。
对于服务器(nginx),日志是这样的,都是1次请求:
27.10.68.64 - - [23/Feb/2018:11:01:32 +0800] "POST //likeme/t.php HTTP/1.1" 200 29 "http://play.whatmiss.com//likeme/" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko" "-"
27.10.68.64 - - [23/Feb/2018:11:01:38 +0800] "POST //likeme/t.php HTTP/1.1" 200 29 "http://play.whatmiss.com//likeme/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.89 Safari/537.36 OPR/49.0.2725.47" "-"
27.10.68.64 - - [23/Feb/2018:11:01:41 +0800] "POST //likeme/t.php HTTP/1.1" 200 29 "http://play.whatmiss.com//likeme/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2" "-"
27.10.68.64 - - [23/Feb/2018:11:01:45 +0800] "POST //likeme/t.php HTTP/1.1" 200 29 "http://play.whatmiss.com//likeme/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0" "-"
27.10.68.64 - - [23/Feb/2018:11:01:51 +0800] "POST //likeme/t.php HTTP/1.1" 200 29 "http://play.whatmiss.com//likeme/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36" "-"
网络资源:
99%的人理解错 HTTP 中 GET 与 POST 的区别: https://www.oschina.net/news/77354/http-get-post-different
不同浏览器发送POST请求分包情况比较: http://blog.csdn.net/someonelikesyou/article/details/8078380
HTTP1.1协议中文版-RFC2616: http://www.cnblogs.com/k1988/archive/2010/01/12/2165683.html
详细截图如下:
IE11浏览器【11.0】,分2次发送:
Opera浏览器【49.0.2725.47】,分1次发送:
Chrome浏览器【64.0.3282.119(正式版本) (64 位)】,分2次发送:
Firefox【57.0.4 (64 位)】,1次发送:
Safari【5.1.7】,2次发送: