curl 命令
curl 命令
此命令可以用来模拟http请求,灰常的厉害,当你手上没有模拟http请求工具的时候,用这个命令简单高效。下面列出几种比较常用的http请求的命令
常用curl实例
只返回结果
curl http://www.baidu.com
返回http header信息和结果
curl -i http://www.baidu.com
解析调用的全部过程
curl -v http://www.baidu.com
将cookie信息保存到文件中
curl -c ./cookie.txt http://www.baidu.com
模拟表单数据提交数据
curl -X POST --data "data=xx" www.baidu.com
curl http://localhost:8080/face/face.do -d '{"service_id":"10001"}'
//将xx/xx.json里面的数据发送,数据很大的时候用
curl http://localhost:8080/face/face.do -d @/xx/xx.json
添加header信息
curl --header "Content-Type:application/json" http://example.com
添加user-agent
curl --user-agent "[User Agent]" http://www.baidu.com
添加来源referer
curl --referer http://localhost:8080 http://www.baidu.com
发送cookie信息
curl --cookie ./cookie.txt www.baidu.com
上传文件
curl --form upload=@localfilename [URL]
FTP
下载
curl -O ftp://用户名:密码@ip:port/demo/xxx.txt
上传
curl -T xxx ftp://用户名:密码@ip:port/demo