概述: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的特徵取不到,會不會就繞過了呢?