Curl用法命令笔记
在linux下curl GET多个参数问题
curl http://mywebsite.com/index.php?a=1&b=2&c=3
$_GET只能获取到参数a
由于url中有&,其他参数获取不到,而且curl会变成后台运行(因为:在linux系统中 & 会使进程系统后台运行)
必须对&进行下转义才能让$_GET获取到所有参数,
正确写法:
curl http://mywebsite.com/index.php?a=1\&b=2\&c=3
指定请求类型:-X
-X POST/PUT/DELETE
传参数:-d
例如:
curl localhost/api/test -X POST -d "title=aa&content=bb"
指定header:-H
例如指定json格式,指定token等
// 指定请求格式为json curl localhost/api/test -H "Content-Type:application/json" // 限制返回格式为json curl localhost/api/test -H "Accept:application/json"
上传文件:-F "file=@__FILE_PATH__"
例如:
// 相对路径 curl localhost/api/test -F file=@report.js // 绝对路径 curl localhost/api/test -F file=@/root/zollty/report.js
更多用法参见:man curl