curl使用

1、curl模拟登录

curl -v -d "user=xxx&password=123456" http://localhost/url

会返回cookie值

-v 查看详细信息
-i 查看头部信息
-d post请求发送的数据,默认以表单的方式提交
-X DELETE 指定请求方法

2、用cookie登录

curl --cookie "xxx" http://localhost/url


3、格式化请求返回的json

curl --cookie "xxx" http://localhost/url | python -m json.tool


4、post json 数据
curl -H Content-Type:application/json -d '{"name":"xxx"}' http://localhost/url


5、url中有多个参数的get请求
&会被linux认为是后台任务,所以要转义
curl http://localhost/url?a=xxx\&b=yyy


或者给url加上双引号
curl “http://localhost/url?a=xxx&b=yyy”



6、获取时间

计时器                            描述
time_connect              建立到服务器的 TCP 连接所用的时间
time_starttransfer    在发出请求之后,Web 服务器返回数据的第一个字节所用的时间
time_total                     完成请求所用的时间


curl www.baidu.com -w "%{time_total}\n"

猜你喜欢

转载自samwalt.iteye.com/blog/2047818