`curl` 是一个非常强大的工具,支持许多参数来定制 HTTP 请求。以下是一些常用的 `curl` 参数及其简单实例:
1. -A, --user-agent <string>
- 设置用户代理。
- 实例:`curl -A "Wget/1.15" http://example.com`
2. -X, --request <command>
- 指定请求的类型(如 GET, POST, PUT 等)。
- 实例:`curl -X POST http://example.com/api/data`
3. -d, --data <data>
- 向服务器发送数据。
- 实例:`curl -d "param1=value1¶m2=value2" http://example.com/api`
4. -F, --form <name=content>
- 上传文件或模拟表单提交。
- 实例:`curl -F "file=@localfile.txt" http://example.com/upload`
5. -G, --get
- 使用 GET 请求发送 -d 参数。
- 实例:`curl -G -d "key=value" http://example.com/api`
6. -H, --header <header>
- 自定义请求头。
- 实例:`curl -H "X-My-Header: 123" http://example.com`
7. -i, --include
- 包括 HTTP 响应头在输出中。
- 实例:`curl -i http://example.com`
8. -I, --head
- 发送 HEAD 请求。
- 实例:`curl -I http://example.com`
9. -L, --location
- 跟随重定向。
- 实例:`curl -L http://example.com/redirect`
10. -o, --output <file>
- 将输出保存到文件。
- 实例:`curl -o output.txt http://example.com/data`
11.-O, --remote-name
- 保存远程文件的原始名称。
- 实例:`curl -O http://example.com/file.zip`
12. -u, --user <user:password>
- 提供用户认证信息。
- 实例:`curl -u username:password http://example.com`
13. -x, --proxy <host:port>
- 使用 HTTP 代理。
- 实例:`curl -x http://proxyserver:port http://example.com`
14. -v, --verbose
- 输出详细的调试信息。
- 实例:`curl -v http://example.com`
15. --trace <file>
- 将所有数据(包括头和体)写入文件。
- 实例:`curl --trace output.txt http://example.com`
16. --trace-ascii
- 类似于 --trace,但以文本形式输出。
- 实例:`curl --trace-ascii http://example.com`
17. -k, --insecure
- 允许连接到 SSL 站点而不需要证书验证。
- 实例:`curl -k https://example.com`
18. --cacert <file>
- 指定 CA 证书用于 SSL 验证。
- 实例:`curl --cacert cacert.pem https://example.com`
19. --cert <cert>
- 指定客户端证书文件。
- 实例:`curl --cert clientcert.pem https://example.com`
20. --key <key>
- 指定私钥文件。
- 实例:`curl --key privatekey.key https://example.com`