curl
是一个用于在命令行中进行网络请求的工具。以下是一些 curl
命令的常见用法:
-
从 URL 下载文件并保存为本地文件:
curl -O URL
例如:
curl -O https://example.com/file.zip
这将会将
file.zip
下载到当前目录。 -
将文件下载到指定位置:
curl -o OUTPUT_PATH URL
例如:
curl -o local_file.zip https://example.com/file.zip
这将会将
file.zip
下载并保存为local_file.zip
。 -
显示 HTTP 头信息:
curl -I URL
例如:
curl -I https://example.com
这将会显示
example.com
的 HTTP 头信息。 -
显示响应内容:
curl URL
例如:
curl https://example.com
这将会显示
example.com
的响应内容。 -
使用 POST 请求发送数据:
curl -X POST -d "key1=value1&key2=value2" URL
例如:
curl -X POST -d "username=admin&password=12345" https://example.com/login
这将会发送 POST 请求,携带参数
username=admin
和password=12345
。 -
使用基本认证进行请求:
curl -u username:password URL
例如:
curl -u admin:12345 https://example.com/api/data
这将使用用户名
admin
和密码12345
进行请求。 -
使用代理进行请求:
curl -x proxy_host:proxy_port URL
例如:
curl -x http://proxy.example.com:8080 https://example.com
这将通过指定的代理服务器
proxy.example.com
和端口8080
发起请求。