curl是一个用于在命令行下传输数据的工具,支持各种协议,包括HTTP、HTTPS、FTP等。以下是一些常见的curl命令用法:
- 发起GET请求
curl https://example.com
- 发起POST请求
curl -X POST -d "key1=value1&key2=value2" https://example.com
- 设置请求头
curl -H "Content-Type: application/json" https://example.com
- 保存输出到文件
curl -o output.txt https://example.com
- 跟随重定向
curl -L https://example.com
- 使用代理
curl -x proxy_host:proxy_port https://example.com
- 基本认证
curl -u username:password https://example.com
- 显示详细的传输信息
curl -v https://example.com
- 设置超时时间
curl --connect-timeout 10 https://example.com
- 发送json数据
curl -X POST -H "Content-Type: application/json" -d '{"key": "value"}' https://example.com
- 上传文件
curl -F "file=@localfile.txt" https://example.com/upload
- 使用代理认证
curl -x proxy_host:proxy_port --proxy-user username:password https://example.com