介绍
curl 是常用的命令行工具,用来请求 Web 服务器。它的名字就是客户端(client)的 URL 工具的意思。
备注:curl官网
GET
curl默认协议就是GET,直接使用 curl url相当于直接用浏览器打开。例如:
curl http://example.com/
POST
curl 使用 -X POST 可以发送POST消息。如果要post json数据,例如:
curl -H "Content-Type:application/json" -X POST -d '{"uid":"123"}' http://127.0.0.1:3000/rest/test
参数解析:
- -H 请求头。post json需要添加 -H “Content-Type: application/json”
- –X 请求协议。
- –d post的body内容,如果是json数据,外层再加一个’包含