curl 简介
curl(CommandLine Uniform Resource Locator),命令行统一资源定位符。是一个利用 URL 规则在命令行下工作的文件传输工具。官方地址是:https://curl.haxx.se/
curl 支持多个操作系统,下载安装非常简单。安装完后,使用下面命令查看使用帮助:
D:Usersxxx>curl -h
Usage: curl [options...] <url>
-d, --data <data> HTTP POST data
-f, --fail Fail silently (no output at all) on HTTP errors
-h, --help <category> Get help for commands
-i, --include Include protocol response headers in the output
-o, --output <file> Write to file instead of stdout
-O, --remote-name Write output to a file named as the remote file
-s, --silent Silent mode
-T, --upload-file <file> Transfer local FILE to destination
-u, --user <user:password> Server user and password
-A, --user-agent <name> Send User-Agent <name> to server
-v, --verbose Make the operation more talkative
-V, --version Show version number and quit
This is not the full help, this menu is stripped into categories.
Use "--help category" to get an overview of all categories.
For all options use the manual or "--help all".
上面只是列出了部分使用帮助,查看全部使用帮助:curl --help all
常用 curl 实例
1. 访问 Restfull 接口
curl -H "Content-Type: application/json" -H "referer: xxx" -X POST --data '{"userName":"Jessica1989","agencyCode":2}' http://xx.xx.xx.xx:8080/admin/xx
上面的命令以 Post 请求的方式,访问某接口,并在请求头中传了 referer 参数。
忽略https证书校验
加上-k参数
curl -H "Content-Type: application/json" -H "referer: xxx" -X POST --data '{"key1":"value1"}' -k https://203.156.238.218:20357