Skip to content
Notes
GitHub

curl 命令的使用

Get 请求

  • -v 表示显示详细请求信息
Terminal window
curl https://www.baidu.com -v
Terminal window
curl https://www.baidu.com -v

Post 请求

  • 通过 -x POST 来声明请求方法
  • -d 添加请求参数
  • -H 声明请求头
Terminal window
curl http://www.baidu.com \
-X POST \
-d "title=comewords&content=articleContent"
Terminal window
curl http://www.baidu.com \
-X POST \
-d "title=comewords&content=articleContent"

通常,我们的请求是 JSON 格式的,可以用单引号将 JSON 字符串括起来

Terminal window
curl http://www.baidu.com \
-X POST \
-H "Content-Type:application/json" \
-d '"title":"comewords","content":"articleContent"'
Terminal window
curl http://www.baidu.com \
-X POST \
-H "Content-Type:application/json" \
-d '"title":"comewords","content":"articleContent"'

POST 上传文件

  • 通过 -F "file=@_FILE_PATH__" 来指定要上传的文件
Terminal window
curl http://www.baidu.com/upimg
-F "file=@/Users/fungleo/Downloads/401.png" \
-H "token: 222" \
-v
Terminal window
curl http://www.baidu.com/upimg
-F "file=@/Users/fungleo/Downloads/401.png" \
-H "token: 222" \
-v