http接口测试必学之curl命令

curl测试GET接口

curl http://www.baidu.com

url参数可以直接写到url中,此时url最好用引号引起来
curl测试带参数get请求

curl 'http://127.0.0.1:5000/add/?a=1&b=2'

表单类Post请求
curl可以通过-d指定 请求数据(包含-d参数时,默认为Post请求),如

curl 'http://127.0.0.1:5000/api/user/login/'  \
-d 'name=张三&password=123456'

JSON格式Post请求
curl可以用个-H指定header,多个header要使用多个-H

curl 'http://127.0.0.1:5000/api/user/reg/' \
-H 'Content-type: application/json' \
-d '{"name":"张三三","password": 123456}'

带Cookie的请求
Cookie属于header的一项,我们可以携带抓取到的Cookie来请求需要登录的接口,如:

curl 'http://127.0.0.1:5000/api/user/getUserList/' \
-H 'Cookie:PYSESSID=xxxxx;session=jeqfqwfwqhfqewfxxxxxx'

可以使用-v参数查看请求详情

posted @ 2022-04-27 14:01  传说中的水牛  阅读(676)  评论(0编辑  收藏  举报