首页 编程 正文
691

curl命令快速测试api的有关选项

  • yiqingpeng
  • 2018-04-15
  • 0
  •  
curl命令在Linux是自带的,在window下需要手动安装。此工具在测试http api方面个人觉得非常好用。下面就列举此命令几个常用的参数(参数是区分大小写的):
-d <post data> : 用post方式提交数据, 如 curl -d "id=123" http://my.com/api
-I :表示只返回header头,不返回body, 如 curl -I  http://my.com/api
-i :同时返回header和body.
-H <header line>: 设置header头, 如 curl -H "User-Agent: wechat" http://my.com/api
curl -H "Host: my.com" http://124.11.22.33/
-L 自动跟踪重定向
-e <referer>: 设置referer, 如 curl -e http://baidu.com http://my.com/api,
在301、302重定向时可以使用 -e ';auto' 自动设置referrer. 例如: curl -I -L -e ';auto' http://www.xxx.com/logout
-D <file>: 将header写入到文件中
-c <file>: 将response返回的cookie写入到文件
-A <string>: 设置用户代理user-agent
-F :表单提交(multipart/form-data)
-X 指定请求方法,如 -X PUT, -X HEAD...
post json: curl -H "Content-Type:application/json" -X POST -d "{\"user\": \"admin\", \"passwd\":\"12345678\"}" http://127.0.0.1:8000/login
-o,--output FILE  将输出保存为文件,可以用来下载文件
-k :忽略证书(测试https接口时有用)
-S 显示错误
-s,--silent  Silent Mode, 不输出任何东西
--socks5 host[:port] 设置socks5代理

自定义header:curl -H "X-OS-NAME:ios" -H "X-OS-VERSION:10" http://xx.xx.xx.xx/app/version 暂时就写这么多。

正在加载评论...