首页 技术 正文
技术 2022年11月18日
0 收藏 379 点赞 3,290 浏览 1608 个字

概述:

在上学的时候,以及在工作的这几年中,我一直错误了理解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.

再次理解HTTP GET协议

和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跟进:

再次理解HTTP GET协议

再次理解HTTP 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的特征取不到,会不会就绕过了呢?

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,105
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,582
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,429
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,836
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,919