再次理解HTTP GET协议

概述:

在上学的时候,以及在工作的这几年中,我一直错误了理解HTTP GET。

以前我的认知中认为GET/POST的区别在于:

1.GET长度限制

2.GET和POST的请求方式不一样(之前所理解的GET传参在URI中,POST是在DATA中)

...

 

问题:

最近刚好在使用openstack相关的security,其中API,请求类似如下:

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数据,

监听端口看看请求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的特征取不到,会不会就绕过了呢?

 

posted @ 2018-09-28 16:48  sevck  阅读(902)  评论(0编辑  收藏  举报