curl — The Command Line Tool for Transferring Data with URLs
curl is the most widely used command-line tool for transferring data with URL syntax. It supports HTTP, HTTPS, FTP, SFTP, and 25+ other protocols. Installed on billions of devices, curl and libcurl are foundational internet infrastructure.
先审查再安装
这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。
npx -y tokrepo@latest install 3552582f-3701-11f1-9bc6-00163e2b0d79 --target codex先 dry-run,确认写入项后再运行此命令。
What it is
curl is a command-line tool and library (libcurl) for transferring data with URL syntax. It supports HTTP, HTTPS, FTP, SFTP, and over 25 other protocols. curl is installed on billions of devices and is the de facto standard for making HTTP requests from the command line and from applications via libcurl.
Developers, sysadmins, and anyone who interacts with APIs or web services uses curl daily. It is the standard tool for testing endpoints, downloading files, and scripting HTTP interactions in shell scripts and CI/CD pipelines.
How it saves time or tokens
curl is a single binary with no dependencies that works identically across Linux, macOS, and Windows. One curl command replaces writing HTTP client code in any programming language. For API testing and debugging, curl commands are shareable, reproducible, and can be directly pasted from documentation.
How to use
- Make a basic GET request:
curl https://api.github.com/users/octocat
- POST JSON data:
curl -X POST https://httpbin.org/post \
-H 'Content-Type: application/json' \
-d '{"name": "test", "value": 42}'
- Download a file with progress:
curl -L -O https://example.com/file.tar.gz
Example
# Send a request with bearer token auth
curl -s https://api.example.com/data \
-H 'Authorization: Bearer sk-your-token' \
-H 'Accept: application/json' | python3 -m json.tool
# Upload a file with multipart form data
curl -X POST https://api.example.com/upload \
-F 'file=@document.pdf' \
-F 'description=Q1 report'
# Follow redirects and save cookies
curl -L -c cookies.txt -b cookies.txt https://example.com/login
Related on TokRepo
- AI tools for API — API development and testing tools
- AI tools for automation — Command-line automation tools
Common pitfalls
- Forgetting
-Lto follow redirects. Many URLs return 301/302 redirects, and without-Lcurl stops at the redirect response. - Not quoting URLs with special characters. Ampersands, brackets, and query strings need proper quoting or escaping in shell environments.
- Using
-kto skip certificate verification in production scripts. This disables TLS security and should only be used for local development.
常见问题
curl supports more protocols (25+ vs wget's HTTP/HTTPS/FTP), outputs to stdout by default (pipe-friendly), and has extensive API via libcurl. wget is better for recursive downloads and mirroring websites. curl is the standard for API interaction; wget is the standard for bulk downloads.
Use -X POST with -d for form data or -d with -H 'Content-Type: application/json' for JSON. For file uploads, use -F for multipart form data. Example: curl -X POST -d '{"key":"value"}' -H 'Content-Type: application/json' https://api.example.com/endpoint.
Yes. curl supports HTTP/2 when built with nghttp2, and HTTP/3 when built with ngtcp2 and nghttp3. Use --http2 or --http3 flags to force a specific version. Most modern curl builds include HTTP/2 support by default.
Use -v (verbose) to see the full request and response headers, TLS handshake details, and connection info. Use --trace or --trace-ascii for even more detail including raw bytes sent and received. Use -w to format specific timing metrics.
Yes. curl supports Basic auth (-u user:pass), Bearer tokens (-H 'Authorization: Bearer token'), digest auth (--digest), NTLM (--ntlm), and client certificates (--cert). It also handles cookies for session-based auth with -c and -b flags.
引用来源 (3)
- curl GitHub— curl supports HTTP, HTTPS, FTP, SFTP and 25+ protocols
- curl Users— libcurl is used in billions of installations worldwide
- curl HTTP/3 Docs— curl supports HTTP/2 and HTTP/3
讨论
相关资产
Transfer.sh — Self-Hosted File Sharing from the Command Line
Transfer.sh is a lightweight file sharing service that lets you upload files from the terminal with a single curl command and share them via auto-generated URLs, supporting encryption, expiration, and multiple storage backends.
jq — Lightweight Command-Line JSON Processor
jq is the essential command-line tool for processing JSON data. It lets you slice, filter, transform, and format JSON with a concise expression language — making it indispensable for working with APIs, config files, and data pipelines in the terminal.
Httpstat — Visualize curl Response Timing Statistics
Httpstat is a command-line tool that visualizes curl HTTP response timing, showing DNS lookup, TCP connection, TLS handshake, server processing, and transfer time in a clear breakdown.
fzf — Blazing Fast Command-Line Fuzzy Finder
fzf is a general-purpose command-line fuzzy finder written in Go. Blazing fast, portable, and composable with any list-producing command. Interactive picker for files, commands, history, git branches, processes, and more.