Updated 8 hours ago
Curl shows you what your code sees.
When your application makes an HTTP request, it doesn't see a rendered webpage. It sees headers, status codes, and raw response bodies. Curl gives you that same view from the command line—the unvarnished truth of what's happening on the wire.
Why This Matters
A web browser hides the HTTP conversation behind rendered HTML and JavaScript execution. Curl strips all that away. You see:
- The exact headers your server sends and receives
- Status codes that tell you what actually happened (not what your app interpreted)
- Response timing down to the millisecond
- The raw body before any parsing or transformation
This transparency makes curl indispensable for testing APIs, debugging failed requests, and understanding why something works in a browser but breaks in your code.
Curl ships with macOS and most Linux distributions. It's been actively developed for over 25 years.
The Basics
Fetch a URL:
You get raw HTML, not a rendered page.
Save the output:
Follow redirects (curl doesn't by default):
Seeing the Conversation
This is where curl becomes powerful.
Include headers in output:
Shows HTTP headers followed by the response body. You see what status code came back, what content type was declared, whether caching headers are set.
Headers only:
Performs a HEAD request—just the headers, no body. Fast way to check if something exists or see server configuration.
The full conversation:
This is curl's most revealing mode. You watch the entire handshake unfold:
- DNS lookup resolving the domain
- TCP connection establishing
- TLS handshake negotiating encryption (for HTTPS)
- Your request headers going out
- Response headers coming back
- The response body
When something fails and you don't know why, -v shows you where it broke.
HTTP Methods
GET (the default):
POST with JSON:
POST with form data:
POST with data from a file:
The @ reads from the file.
PUT, PATCH, DELETE:
Headers and Authentication
Set headers with -H:
Basic authentication:
API keys:
Cookies
Send a cookie:
Save cookies from a response:
Use saved cookies:
File Uploads
The -F flag sends multipart/form-data, which is what servers expect for file uploads.
Timing and Performance
Get total request time:
Detailed timing breakdown:
Just the status code:
Testing and Debugging
Set timeouts:
Fails if connection takes over 5 seconds or total request exceeds 10 seconds.
Force a specific TLS version:
Test before DNS propagates:
Forces curl to resolve the domain to your specified IP. Useful for testing a new server before switching DNS.
Ignore SSL errors (testing only):
Never use -k in production. It disables certificate validation entirely.
Proxies
Scripting
Check if a site is up:
Get the status code into a variable:
Useful flags for scripting:
-ssuppresses progress output-Sshows errors even when-sis used-freturns non-zero exit code on HTTP errors (404, 500, etc.)-o /dev/nulldiscards the response body
Security
Never ignore SSL errors in production. The -k flag makes you vulnerable to man-in-the-middle attacks.
Protect credentials. Don't put passwords in commands that will appear in shell history:
Be careful with -v output. It shows your authentication headers. Don't paste verbose output into public issue trackers.
Quick Reference
| Flag | Purpose |
|---|---|
-X METHOD | HTTP method (GET, POST, PUT, DELETE, PATCH) |
-H "Header: Value" | Set request header |
-d "data" | Send data in request body |
-F "field=@file" | Upload file (multipart/form-data) |
-i | Include response headers in output |
-I | Headers only (HEAD request) |
-v | Verbose—show full HTTP conversation |
-L | Follow redirects |
-o file | Save output to file |
-O | Save with original filename |
-s | Silent mode |
-w "format" | Custom output format (timing, status code) |
-u user:pass | Basic authentication |
-b "cookie" | Send cookie |
-c file | Save cookies to file |
Frequently Asked Questions About curl
Was this page helpful?