curl工具的使用方法
概述
这篇文章介绍了一个开源功能强大的命令行网络工具 curl,curl 功能丰富,用法简单,被广泛用于命令行、终端的网络请求场景中。这篇文件简要介绍了 curl 的功能和使用方法。
curl 是什么
curl 是一个命令行工具,利用 URL 语法在命令行中完成数据传输的工具,支持文件上传和下载。
curl 支持的协议(参考官网介绍):
| 协议 | 详情 |
|---|---|
| Protocol | DICT, FILE, FTP, FTPS, GOPHER, GOPHERS, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, MQTT, POP3, POP3S, RTMP, RTMPS, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET, TFTP, WS, WSS |
| Proxies | SOCKS4, SOCKS5, HTTP, HTTPS (HTTP/1 and HTTP/2), tunneling, via unix domain sockets, haproxy, SOCKS+HTTP proxy chain |
| HTTP | GET, POST, PUT, HEAD, multipart formpost, HTTP/0.9, HTTP/1.0, HTTP/1.1, HTTP/2 (h2c, h2, prior knowledge), HTTP/3 (dual connect h1/h2 + h3 or h3-only), HSTS, Alt-Svc, cookies, PSL, etags, transfer compression, ranges, custom headers, custom method, follow redirects |
| FTP | IPv6 (EPRT, EPSV), STLS, upload/download, append, range, passive/active, kerberos, directory listing, custom commands |
| SCP + SFTP | known hosts, md5/sha256 fingerprint, compression, upload/download, directory listing |
| TLS | 1.0 - 1.3, mutual authentication, STARTTLS, OCSP stapling, ECH, False Start, key pinning, PQC ready, session resumption, early data, export/import sessions |
| QUIC | 0RTT handshakes |
| Auth | Basic, Plain, Digest, CRAM-MD5, SCRAM-SHA, NTLM, Negotiate, Kerberos, Bearer tokens, AWS Sigv4, SASL, .netrc |
| HTTP compression | gzip, brotli and zstd |
| Name resolving | DNS-over-HTTPS, custom address for host, name+port redirect, custom DNS servers, DNS caching, HTTPS RR |
| Connection | connection reuse, Interface binding, Happy Eyeballs, IPv4/IPv6-only, unix domain sockets, TCP keepalive, TCP Fast Open, TCP Nodelay, MPTCP, VLAN priority, IP Type Of Service |
| Transfers | transfer rate limiting, request rate limiting, stall detection, retries, timeouts |
| URLs | Unlimited amount, parallel and serial transfers, globbing |
| Output | IDN hostnames, custom info from transfer, metadata as JSON, per content-disposition, libcurl source code, bold headers |


