一、curl命令介绍
curl(CommandLine Uniform Resource Locator),是一个利用 URL 语法,在命令行终端下使用的网络请求工具,支持 HTTP、HTTPS、FTP 等协议。curl也有用于程序开发使用的版本 libcurl。
Linux、MAC 一般系统默认已安装好 curl,直接在终端使用命令即可,如果需要手动安装,可以到 curl.haxx.se 下载安装。
Windows 系统 curl 下载地址: curl for Windows,下载解压后即可使用,命令的可执行文件在解压后的 bin 文件夹中。
二、基础语法
curl [options...] [url]
2.1 基础用法
curl http://example.com
2.2 使用-o将下载的数据写到本地文件中
curl -o linux.html http://example.com
2.3 测试网络返回值
curl -o /dev/null -s -w "%{http_code}\n" http://example.com
2.4 指定代理服务器以及端口
curl -x 192.168.99.99:8888 http://example.com
2.5 使用curl命令来访问URL并查看响应时间
curl -o /dev/null -s -w "返回状态码:%{http_code}\n响应时间: %{time_connect}\nTime to first byte: %{time_starttransfer}\nTotal time: %{time_total}\n" http://example.com
image.png