GET vs. POST

工作中,最常用的两个HTTP的Method:GET、POST。用大白话说,GET用于“获取”数据(即“读”),POST用于“提交”数据(即“写”)。当然,这样的区别仅是就“用途”方面,也是“软”规则(实际上如果Server端实现比较“二”的话,GET方法也可能有“改变数据”的操作)。

从“协议”角度(浏览器等的实现)来说(即“硬”规则),二者的主要区别有:

  • GET请求所带数据只能放在URL中,而POST的则可以放在Request Body中 [关键区别]
  • GET请求所带数据长度有限制,POST无限制

因此,有几个常见的迷惑就有答案了:

  1. 上传图片,只能用POST(把图片数据写在URL中?一般人不这么干)
  2. jsonp不支持POST方法 (jsonp本就是GET方法实现的,还怎么POST咧? more...

GET

The GET method requests a representation of the specified resource. Requests using GET should only retrieve data and should have no other effect. (This is also true of some other HTTP methods.) The W3C has published guidance principles on this distinction, saying, "Web application design should be informed by the above principles, but also by the relevant limitations."

POST

The POST method requests that the server accept the entity enclosed in the request as a new subordinate of the web resource identified by the URI. The data POSTed might be, for example, an annotation for existing resources; a message for a bulletin board, newsgroup, mailing list, or comment thread; a block of data that is the result of submitting a web form to a data-handling process; or an item to add to a database.

ref:

  1. wiki
  2. StackOverflow
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,500评论 0 23
  • 就算不说,也要知道的社会规则 1. 不要轻易把心底深处不愿示人的部分坦露出来,靠同情轻易获得的朋友,内心不一定看得...
    素然威哥阅读 1,616评论 0 0

友情链接更多精彩内容