curl http header_「测试」 - 接口测试 & curl
对于接口文档,有时会使用Linux下的curl的方式给出,很多接口测试工具也支持将测试用例导出为curl格式。对于后端测试,还是需要掌握curl,进行接口快速验证。# http://jwd.funnyapi.com/#/index经纬度行政区域查询接口APIhttp://116.196.105.215:1234/gis使用curl测试curl 'http://116.196.105.2...
·
对于接口文档,有时会使用Linux下的curl的方式给出,很多接口测试工具也支持将测试用例导出为curl格式。对于后端测试,还是需要掌握curl,进行接口快速验证。
# http://jwd.funnyapi.com/#/index
经纬度行政区域查询接口API
http://116.196.105.215:1234/gis
使用curl测试
curl 'http://116.196.105.215:1234/gis?auth_user=freevip&latitude=39.880655&longitude=116.354386'
curl是非常方便的Rest客户端,可以很方便的完成Rest API测试,利用curl对http协议发送GET、POST、DELETE、PUT,同时还支持携带header来满足Rest API需求的特定条件。
一、curl常用的参数
- -X/--request,指定http method
- -H/--header,设定request里的header
- -i/--include,显示response的header
- -d/--data,设定http parameters
- -v/--verbose,输出详细信息
- -u/--user,使用者账号
- -b/--cookie,cookie文件路径
二、实战
A、设置header
# 设置header
curl -i -H "Content-Type: text/plain; charset=UTF-8" http://10.255.242.157:8082/preorder/query?orderId=1013035382550
B、设置parameter
# 设置parameter
curl -X POST -d "param1:value1¶m2=value2"
或者
curl -X POST -d "param1=value1" -d "param2=value2"
curl -i -X POST -d "partnerId=29&remark=价格&userMail=isisiwish#qq.com&userName=isisiwish" http://10.255.242.128:8888/alarm/email/add
C、使用cookie
# 使用cookie文件
curl -i --header "Content-Type:application/json" -X GET -b cookie.txt http://www.baidu.com
# 使用header传递cookie
curl 'https://www.zhihu.com/api/v4/me?include=email' -H 'cookie: _xsrf=xxoo'
D、文件上传
# 文件上传
curl -i -X POST -F 'file=@/User/uploadFile.txt' -H "token:abc123" -v
E、HTTP Basic Authentication
# HTTP基本认证(HTTP Basic Authentication)
curl -i -u root:root 'http://10.255.242.168:12306/governance/services'
F、xml或json作为参数
# json作为直接入参
curl -i -H 'Content-Type:application/json' -X POST -d '{"partnerId": "28","addressCn": "安徽省|亳州市|利辛县"}' 'http://10.255.242.168:8500/address/ddAddressGet'
更多推荐
已为社区贡献2条内容
所有评论(0)