curl Command Cheat Sheet: Headers, Auth, Files & Debugging

Copy-ready curl commands for REST testing, custom headers and auth, file uploads, redirects and TLS inspection, timing breakdowns and the verbose flags that explain a failed request.

Interactive Target Variable Replacer

Change the target IP or host and the target domain below and every command block on this page updates to match.

Command Reference

1. Inspect Response Headers Only

Send a HEAD-style request with -I to see status, server, cache and security headers without downloading the body.

curl -sI https://192.0.2.10

2. Show Headers and Body Together

Verbose for humans: -i prints the response headers, a blank line, then the body.

curl -si https://192.0.2.10/api/health

3. Follow Redirects and Show the Chain

Track the full 301/302 chain, which is how you confirm a canonical redirect actually lands where it should.

curl -sIL https://192.0.2.10 | grep -iE "^HTTP/|^location:"

4. Send JSON with a Custom Header

The standard shape of an authenticated API request: content type, token and a JSON body.

curl -s -X POST https://192.0.2.10/api/login -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" -d '{"user":"admin"}'

5. Upload a File as Multipart

Force a multipart body with -F; useful for testing upload validation and content-type checks.

curl -s -F "file=@./shell.php;type=image/png" -F "name=test" https://192.0.2.10/upload

6. Basic Auth Without Leaking in Shell History

Pass credentials with -u so curl handles the Base64 encoding; use the prompt so the password is not in history.

curl -s -u admin https://192.0.2.10/private

7. Test a Specific Host Header

Point the request at one IP but claim a different Host, which is the quickest way to find a misrouted vhost.

curl -s -H "Host: internal.example.com" https://192.0.2.10/

8. Find Where a Request Spends Its Time

The timing breakdown that separates DNS, TCP, TLS, waiting and transfer - the first step in any slow-endpoint investigation.

curl -s -o /dev/null -w "dns:%{time_namelookup} connect:%{time_connect} tls:%{time_appconnect} ttfb:%{time_starttransfer} total:%{time_total}\n" https://192.0.2.10

9. Check What Status a Redirect Chain Ends On

One number, after following every hop - the check to run after any routing or domain change.

curl -s -o /dev/null -w "%{http_code} %{url_effective}\n" -L https://192.0.2.10/some/old/path

10. Inspect the TLS Certificate the Server Sends

Print the certificate and handshake details without opening a browser.

curl -sv https://192.0.2.10 -o /dev/null 2>&1 | grep -A2 "Server certificate"

11. Send Cookies From a Saved Session

Save cookies during a login and replay them on later requests, which is how authenticated flows are scripted.

curl -s -c cookies.txt -d "user=admin&pass=test" https://192.0.2.10/login && curl -s -b cookies.txt https://192.0.2.10/dashboard

12. Retry and Bound the Request

Timeouts and retries belong on every automated curl call; without them a hung endpoint hangs the job.

curl -s --max-time 15 --retry 2 --retry-delay 1 https://192.0.2.10/status

Frequently Asked Questions

What is the difference between -i, -I and -v?

-i includes the response headers in the output alongside the body. -I sends a HEAD request instead of GET, so you get headers and no body at all. -v writes the whole conversation - request line, request headers, TLS details and response headers - to stderr, which is what you want when a request fails for a reason the body does not explain.

Why does curl return nothing when the URL works in a browser?

Usually one of four things: the site needs a header the browser sent automatically, the request is being redirected and you did not pass -L, the response is compressed and you are piping it somewhere that mangled it, or the browser had a cookie. Start with -v and read the request headers curl actually sent.

How do I stop curl from leaking a token in shell history?

Prefix the command with a space if your shell has HISTCONTROL=ignorespace, or pass the value from an environment variable that you read from a file. Do not paste production tokens into a shared terminal; a leaked credential in history is a real incident, not a nuisance.

Is curl safe to point at a target I am testing?

Only for the same reason any request is safe: because you are authorised. curl itself does not exploit anything, but sending crafted requests to a system you do not own is unauthorised access regardless of the tool.


Related Guides, Tools & Cheat Sheets