用curl:
curl -X GET "127.0.0.1:8001" -d "{'a':1,'b':2}"
用python requests:
import requests requests.get(url="127.0.0.1:8001", data={'a':1,'b':2})
參考:https://juejin.im/entry/5badb020f265da0ac962abf2
當我們被問及 HTTP 的 GET 與 POST 兩種請求方式的區別的時候,很多答案是說 GET 的數據須通過 URL 以 Query Parameter 來傳送 ,而 POST 可以通過請求體來發送數據,所以因 URL 的受限,往往 GET 無法發送太多的字符。
GET 果真不能通過 Request Body 來傳送數據嗎?
非也。
如此想法多半是因循着網頁中 form 的 method 屬性只有 get 與 post 兩種而來。
因為把 form 的 method 設置為 post,表單數據會放在 body 中,而 method 為 get(默認值) 時,提交時瀏覽器會把表單中的字符拼接到 action 的 URL 后作為 query parameter 傳送。
GET vs POST
於是乎就有了這么一種假像:HTTP GET 必須通過 URL 的查詢參數來發送數據。
其實 HTTP 規范並未規定說 GET 就不能發送 body 數據,在 RFC GET 中只是說:
The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI.