正常的认知中,GET 是不可以使用 body 的,如果要使用 body,可以转化成 querystring。
查了些资料,发现规范并没有限制,但是实际使用是有很大区别的。
使用 Go 实现一个 Server,然后使用 curl(v7.54.0),nodejs(v13.5.0),go(v1.13.5) 来实验:
1 | package main |
使用 Go client
1 | package main |
Server 正常打印。
使用 curl
1 | curl --location --request GET 'localhost:8000' --data-raw 'hello,world' |
Server 正常打印,另外 Content-Type 也自动加上了 application/x-www-form-urlencoded。
使用 nodejs 的话,就有很大区别,GET 不会传递 body,而 POST 会。
1 | // nodejs version v13.5.0 |
切换到 postman 实现,postman 是支持 GET with body 的。