linux带参数post调用接口,CURL命令模拟Http Get/Post以及带cookies调用接口

在对后端程序进行测试的时候,需要进行模拟连接或者书写测试脚本.

curl是一个很棒的命令.

例如目标网站Url:

127.0.0.1:8080/check_your_status?user=Summer&passwd=12345678

通过Get方法请求:

curl protocol://address:port/url?args

curl http://127.0.0.1:8080/check_your_status?user=Summer&passwd=12345678

通过Post方法请求:

curl -d "args" "protocol://address:port/url"

curl -d "user=Summer&passwd=12345678" "http://127.0.0.1:8080/check_your_status"

这种方法是参数直接在header里面的

如需将输出指定到文件可以通过重定向进行操作.

curl -H "Content-Type:application/json" -X POST --data (json.data) URL

curl -H "Content-Type:application/json" -X POST --data '{"message": "sunshine"}' http://localhost:8000/

这种方法是json数据直接在body里面的

使用Curl命令查看请求响应时间方法

curl -o /dev/null -s -w %{time_namelookup}::%{time_connect}::%{time_starttransfer}::%{time_total}::%{speed_download}"\n" http://www.36nu.com

0.014::0.015::0.018::0.019::1516256.00

编写测试实例:

curl -b “user_trace_token=20150518150621-02994ed9a0fb42d1906a56258e072fc4;LGUID=20150515135257-a33a769c-fac6-11e4-91ce-5254005c3644” http://10.10.26.164:1235/click?v=1&logtype=deliver&position=home_hot-0&orderid=10197777&userid=1942556&positionid=148&url=http%3a%2f%2fwww.lagou.com%2fjobs%2f317000.html%3fsource%3dhome_hot%26i%3dhome_hot-5&fromsite=http%3a%2f%2fwww.lagou.com%2fzhaopin%2fAndroid%3flabelWords%3dlabel%26utm_source%3dAD__baidu_pinzhuan%26utm_m

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值