概述:shell
在上学的时候,以及在工做的这几年中,我一直错误了理解HTTP GET。json
之前个人认知中认为GET/POST的区别在于:api
1.GET长度限制浏览器
2.GET和POST的请求方式不同(以前所理解的GET传参在URI中,POST是在DATA中)安全
...服务器
问题:app
最近恰好在使用openstack相关的security,其中API,请求相似以下:curl
curl -H 'Content-Type: application/json'
-X GET
--data '{"username":"foo","password":"bar"}'"http://www.a.com:1234/apiname" | jq .
curl指定GET请求,加了--data参数,也就是说GET请求发送data数据,ide
监听端口看看请求raw的样子 :函数
e.g.
和POST无外乎请求方式不同,可是实际上的内容是同样的。
也就是说GET请求实际上也是能够带DATA来进行发送数据的。
在RFC GET请求中是这样说明的:
The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI.
并无说GET必定不能从data来发送数据。
BTW:
为何你们都是GET URI传参,POST 使用data传参呢?
查了一些资料,目前总结2点是比较重要的:
1. 目前的类库,例如http requests,浏览器/服务器等GET就是经过URI传参,POST经过data,Postman插件的GET也是同理,默认已经达成默契,行业规范是这样作,GET不容许包含消息主体,POST能够。
可是我又这种需求,怎么解决:
Python requests包源码,requests.get跟进:
复用post函数代码,request第一个参数修改get便可。
2.在RCF设计HTTP 请求方式时,规定GET为取数据,POST为发送数据。只不过目前在开发设计中未真正遵循这个规范罢了。
若是非要在GET上加消息请求体,那么和POST又有什么区别了呢...
stackoverflow中有一个很正确的回答:(https://stackoverflow.com/questions/978061/http-get-with-request-body?answertab=active#tab-top)
Yes. In other words, any HTTP request message is allowed to contain a message body, and thus must parse messages with that in mind. Server semantics for GET,
however, are restricted such that a body, if any, has no semantic meaning to the request. The requirements on parsing are separate from the requirements on method semantics. So, yes, you can send a body with GET, and no, it is never useful to do so. This is part of the layered design of HTTP/1.1 that will become clear again once the spec is partitioned (work in progress). ....Roy
关于安全:
既然GET和POST实质上本质并不大,可是我相信国内安全厂商检测确定是GET取URI的参数,POST取data的内容
例如:
中X菜刀估计国内外的WAF都有拦截。
若是菜刀发送的是GET,内容是在消息体,服务器上的shell接收的是GET,取得是GET中的data数据,那么WAF认为是GET,URI的特征取不到,会不会就绕过了呢?