背景:在平时开发时,很多时候会涉及到对接三方系统,调其他三方系统接口,或是提供接口给他人(下游系统)使用。http接口的开发一直伴随平时项目开发,联调接口是必不可少的一项工作。
平时联调接口常用的三种方式:Linux中的curl、浏览器、postman工具。
下面主要介绍Linux中的curl命令,简单快捷。
Linux curl GET请求
curl 请求接口 -v 可以查看此次发送的请求中详细信息
1 -v/--verbose
2 Makes the fetching more verbose/talkative. Mostly useful for debugging. A line starting with ’>’ means "header data" sent by curl, ’<’
3 means "header data" received by curl that is hidden in normal cases, and a line starting with ’*’ means additional info provided by curl.
4
5 Note that if you only want HTTP headers in the output, -i/--include might be the option you’re looking for.
6
7 If you think this option still doesn’t give you enough details, consider using --trace or --trace-ascii instead.
8
9 This option overrides previous uses of --trace-ascii or --trace.
10
11 Use -s/--silent to make curl quiet.
命令为:
1[ylyao4@localhost testCurl]$ curl http://www.baidu.com
Linux curl POST请求
curl -X POST '接口地址' -H 'content-Type:application/json' -d '请求参数'
命令为:
1[ylyao4@localhost testCurl]$ curl -X POST 'localhost:80/addErrorLog' -H 'content-Type:application/json' -d '{"message":"A Test","errorType":"ERROR"}'
Linux curl的其他用法
保存访问的网页
命令为:
1[ylyao4@localhost testCurl]$ curl http://www.baidu.com >> baidu.html
保存http的response中的cookie信息
命令为:
1[ylyao4@localhost testCurl]$ curl -c cookiec.txt http://www.baidu.com
还可以通过ftp下载文件、显示下载进度条、上传文件、显示抓取错误等,涉及其他参数可使用命令 man curl 参看
方式多种,选择适合自己的


文章转载自testDemo,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




