TL;DR
curl is the first tool for API debugging. Essentials: curl -sS URL, curl -X POST -H 'Content-Type: application/json' -d '{}' URL, curl -w '%{http_code}'.
Basic Requests
| Need | Command |
|---|
| GET with headers in output | curl -i URL |
| Silent mode | curl -sS URL |
| Headers only | curl -I URL |
| Follow redirects | curl -L URL |
| Save to file | curl -o file.txt URL / -O |
Sending Data
| Need | Command |
|---|
| POST JSON | curl -X POST -H 'Content-Type: application/json' -d '{"k":"v"}' URL |
| Form data | curl -d 'k=v&k2=v2' URL |
| Upload file | curl -F 'file=@./a.txt' URL |
| Custom header | curl -H 'Authorization: Bearer TOKEN' URL |
| Cookies | curl -b 'name=value' URL |
Useful Flags
| Flag | Purpose |
|---|
-w '%{http_code}\n' | Print status code only |
--max-time 10 | Timeout (seconds) |
--connect-timeout 5 | Connect timeout |
-k | Skip TLS verification (debug only) |
-x http://host:port | Use proxy |
-A 'UA' | Custom User-Agent |
Debugging Notes
- Status 000 = connection failure/timeout; add
--max-time and -v. -v shows handshake and header details.curl -s -o /dev/null -w '%{http_code}' is the standard script pattern.
Sources
- curl docs (curl.se/docs/manpage.html)
最后更新:2026-08-02