The curl Command: A Practical Guide

curl is a free command-line tool for sending requests to servers and seeing exactly what comes back. It’s installed by default on Windows 10 and later, macOS and most Linux distributions, which makes it one of the most useful tools for testing websites and APIs, troubleshooting connections and checking security settings, all without opening a browser.

Basic Syntax
curl [options] <URL>
With no options, curl sends a GET request and prints the response body to the screen. Options change the request method, add headers or data, save output to a file, or show more detail about the connection. If you’re new to how requests and responses work, start with our overview of how web requests work.
Most Useful Options
| Option | What it does |
|---|---|
-I, --head | Fetch only the response headers |
-i, --include | Show headers along with the body |
-v, --verbose | Show the full conversation, including the TLS handshake |
-L, --location | Follow redirects |
-o / -O | Save output to a named file / to the remote file’s name |
-X, --request | Set the HTTP method (POST, PUT, DELETE and so on) |
-H, --header | Add a custom request header |
-d, --data | Send data in the request body (implies POST) |
-u, --user | Send basic authentication credentials |
-s, --silent | Hide the progress meter, useful in scripts |
Windows tip: In Windows PowerShell, curl may be an alias for a different built-in command. Type curl.exe to make sure you’re running the real curl.
Practical Examples
Check a site’s headers and security settings
curl -I https://www.example.com
The response shows the status code, server details and security headers. It’s a quick way to confirm whether a site sends headers like Strict-Transport-Security or Content-Security-Policy.
Confirm HTTP redirects to HTTPS
curl -IL http://www.example.com
Following the redirects shows each hop, so you can verify that visitors who type http:// are sent to the secure version of your site.
Troubleshoot a connection or certificate
curl -v https://www.example.com -o /dev/null
Verbose mode shows DNS resolution, the TLS version, the server’s certificate and its expiration date, and every header sent and received. The -o /dev/null discards the page body (use -o NUL on Windows).
Download a file
curl -L -O https://www.example.com/files/report.pdf
Send JSON to an API
curl -X POST https://api.example.com/v1/items \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_TOKEN" \
-d '{"name": "test item"}'
Reading the token from an environment variable ($API_TOKEN) keeps it out of the command itself.

Use curl Safely
- Don’t disable certificate checks. The
-k(--insecure) option skips certificate verification and removes the protection HTTPS provides. Fix the certificate problem instead, and never use-kin scripts that run in production. - Keep secrets off the command line. Passwords and tokens typed directly into a command can end up in shell history and process lists. Use environment variables, a credentials file, or let curl prompt for the password by entering only the username with
-u. - Think twice before piping to a shell. Install instructions that run
curl ... | shexecute whatever the server sends. Download the script first, review it, and verify any published checksum before running it. - Only test systems you’re authorized to test. Sending requests to someone else’s application to probe for weaknesses without permission can violate laws and terms of service.
The Bottom Line
curl is one of the simplest ways to see how a website or API really behaves: which headers it sends, where it redirects, and what its certificate looks like. A handful of options covers most everyday tasks. If you’d like help reviewing your website’s security configuration, contact us.
0 Comments