99% of people misunderstood the difference between get and post in http

Wu Ge chat programming 2020-11-12 22:39:01
people misunderstood difference post http


GET and POST yes HTTP Two basic methods of requesting , The difference between them , Come into contact with WEB Developers can say one or two .

The most intuitive difference is GET Include the parameter in URL in ,POST adopt request body Pass parameters .

You may have written countless GET and POST request , Or have seen many authoritative websites summarize their differences , You know exactly when and what to use .

When you are asked this question in an interview , Your heart is full of confidence and joy .

You give me a “ The standard answer ”:

  • GET It is harmless when the browser is backout , and POST The request will be submitted again .

  • GET Produced URL The address can be Bookmark, and POST Can not be .

  • GET The request will be initiated by the browser cache, and POST Can't , Unless manually set .

  • GET Request can only proceed url code , and POST Supports a variety of coding methods .

  • GET The request parameters are fully preserved in the browser history , and POST The parameters in are not retained .

  • GET Request in URL There is a length limit on the parameters passed in , and POST It has a .

  • The data type for the parameter ,GET We only accept ASCII character , and POST There is no limit to .

  • GET Than POST It's not safe , Because the parameters are directly exposed to URL On , So it can't be used to convey sensitive information .

  • GET Parameters through URL Pass on ,POST Put it in Request body in .

( The answers to this standard are from w3schools)

 

“ unfortunately , This is not the answer we want !”

 

Please tell me the truth ...

If I told you GET and POST Is there no difference in essence between you and me ? 
Let's peel off GET and POST The appearance of , Let's be honest !

GET and POST What is it? ?HTTP Two ways to send requests in the protocol .

HTTP What is it? ?HTTP Is based on TCP/IP Protocol for how data is communicated on the world wide web .

HTTP The bottom is TCP/IP. therefore GET and POST The bottom layer is also TCP/IP, in other words ,GET/POST All are TCP link .GET and POST You can do the same thing . Do you want to GET add request body, to POST close url Parameters , Technically, it works perfectly . 

that ,“ The standard answer ” What are the differences in ?

In my world of the World Wide Web ,TCP It's like a car , We use it TCP To transport data , It is very reliable , It never happens that fewer pieces are lost . But if we run as like as two peas, we'll run the same cars. , So the world looks like a mess , An urgent car may be blocked by a car full of goods ahead , The whole transportation system will be paralyzed . To avoid that , traffic rules HTTP The birth of .HTTP There are several service categories for car transportation , Yes GET, POST, PUT, DELETE wait ,HTTP Regulations , When executed GET On request , To put a sticker on the car GET The label of ( Set up method by GET), And we need to put the transmitted data on the roof (url in ) To facilitate recording . If it is POST request , It's going to be pasted on the car POST The label of , And put the goods in the carriage . Of course , You can also be in GET Sneak some goods into the car , But it was disgraceful ; It can also be in POST Put some data on the roof of the car , It feels silly .HTTP It's just a code of conduct , and TCP It's just GET and POST How to achieve the basic .

however , We only see HTTP Yes GET and POST Parameter transmission channel (url still requrest body) Put forward a request .“ The standard answer ” Where does the parameter size limit come from ?

 

In my world of the World Wide Web , There is another important role : Transportation company . Different browsers ( launch http request ) And the server ( Accept http request ) Just different shipping companies . Although theoretically , You can pile unlimited loads on the roof (url And an infinite number of arguments ). But transportation companies are not stupid , Loading and unloading are also very costly , They will limit the number of shipments to limit the risk , Too much data is a burden on both the browser and the server . The unwritten rule in the industry is ,( majority ) Browsers often restrict url The length is in 2K Bytes , and ( majority ) Maximum server processing 64K The size of url. More than , We will not deal with it . If you use GET service , stay request body Hiding the data , Different servers do different things , Some servers will unload for you , Read the data , Some servers just ignore it , therefore , although GET You can take request body, There is no guarantee that it will be received .

Okay , Now you know ,GET and POST It's essentially TCP link , There is no difference . But because of HTTP The rules and browsers / Server limitations , As a result, they show some differences in the application process . 

You think this is the end of the article ?

Our big BOSS Still waiting to show up ...

the BOSS How mysterious ? When you try to find “GET and POST The difference between ” When , In the search results you'll see , Never mentioned him . What on earth is he ...

GET and POST There is another important difference , To put it simply :

GET Produce a TCP Data packets ;POST Produce two TCP Data packets .

Long talk :

about GET Method request , The browser will http header and data Send along , Server response 200( Return the data );

And for POST, Browser sends first header, Server response 100 continue, The browser sends data, Server response 200 ok( Return the data ).

in other words ,GET It only takes a car trip to get the goods to , and POST Have to run two , The first trip , Go and say hello to the server first “ hi , I have to deliver a shipment later , You open the door to meet me ”, Then go back and deliver the goods .

because POST Two steps are needed. , It takes a little more time , look GET Than POST More effective . therefore Yahoo The team has recommended GET Replace POST To optimize website performance . But this is a pit ! Jump in with caution . Why? ?

1. GET And POST Each has its own semantics , You can't mix them .

2. According to research , In a good network environment , The difference between the time to send a packet and the time to send two packets is negligible . And in the case of bad network environment , The two packages TCP On verifying packet integrity , It has great advantages .

3. Not all browsers will be there POST Send two packets in ,Firefox Just send it once .

Now? , When the interviewer asks you “GET And POST The difference between ” When , Is that the way you are inside ?

 

Source of the article :http://t.cn/RjLq41J

----------------------------------------------------------------------------------------------

Welcome to my WeChat official account. , Every day in the morning 9:00 Push articles on time .

After scanning the code , reply “ resources ” perhaps “ framework ” You can get massive high-quality video resources .

版权声明
本文为[Wu Ge chat programming]所创,转载请带上原文链接,感谢

  1. [front end -- JavaScript] knowledge point (IV) -- memory leakage in the project (I)
  2. This mechanism in JS
  3. Vue 3.0 source code learning 1 --- rendering process of components
  4. Learning the realization of canvas and simple drawing
  5. gin里获取http请求过来的参数
  6. vue3的新特性
  7. Get the parameters from HTTP request in gin
  8. New features of vue3
  9. vue-cli 引入腾讯地图(最新 api,rocketmq原理面试
  10. Vue 学习笔记(3,免费Java高级工程师学习资源
  11. Vue 学习笔记(2,Java编程视频教程
  12. Vue cli introduces Tencent maps (the latest API, rocketmq)
  13. Vue learning notes (3, free Java senior engineer learning resources)
  14. Vue learning notes (2, Java programming video tutorial)
  15. 【Vue】—props属性
  16. 【Vue】—创建组件
  17. [Vue] - props attribute
  18. [Vue] - create component
  19. 浅谈vue响应式原理及发布订阅模式和观察者模式
  20. On Vue responsive principle, publish subscribe mode and observer mode
  21. 浅谈vue响应式原理及发布订阅模式和观察者模式
  22. On Vue responsive principle, publish subscribe mode and observer mode
  23. Xiaobai can understand it. It only takes 4 steps to solve the problem of Vue keep alive cache component
  24. Publish, subscribe and observer of design patterns
  25. Summary of common content added in ES6 + (II)
  26. No.8 Vue element admin learning (III) vuex learning and login method analysis
  27. Write a mini webpack project construction tool
  28. Shopping cart (front-end static page preparation)
  29. Introduction to the fluent platform
  30. Webpack5 cache
  31. The difference between drop-down box select option and datalist
  32. CSS review (III)
  33. Node.js学习笔记【七】
  34. Node.js learning notes [VII]
  35. Vue Router根据后台数据加载不同的组件(思考->实现->不止于实现)
  36. Vue router loads different components according to background data (thinking - & gt; Implementation - & gt; (more than implementation)
  37. 【JQuery框架,Java编程教程视频下载
  38. [jQuery framework, Java programming tutorial video download
  39. Vue Router根据后台数据加载不同的组件(思考->实现->不止于实现)
  40. Vue router loads different components according to background data (thinking - & gt; Implementation - & gt; (more than implementation)
  41. 【Vue,阿里P8大佬亲自教你
  42. 【Vue基础知识总结 5,字节跳动算法工程师面试经验
  43. [Vue, Ali P8 teaches you personally
  44. [Vue basic knowledge summary 5. Interview experience of byte beating Algorithm Engineer
  45. 【问题记录】- 谷歌浏览器 Html生成PDF
  46. [problem record] - PDF generated by Google browser HTML
  47. 【问题记录】- 谷歌浏览器 Html生成PDF
  48. [problem record] - PDF generated by Google browser HTML
  49. 【JavaScript】查漏补缺 —数组中reduce()方法
  50. [JavaScript] leak checking and defect filling - reduce() method in array
  51. 【重识 HTML (3),350道Java面试真题分享
  52. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  53. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  54. [re recognize HTML (3) and share 350 real Java interview questions
  55. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  56. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  57. 【重识 HTML ,nginx面试题阿里
  58. 【重识 HTML (4),ELK原来这么简单
  59. [re recognize HTML, nginx interview questions]
  60. [re recognize HTML (4). Elk is so simple