curl
Transfer data from or to a server using URLs with curl — test APIs, debug HTTP headers, download files, and troubleshoot connections.
- curl
- What curl Does and When to Use It
- How to Install curl
- Core Concepts of curl
- curl Request Methods
- curl Headers and Output
- curl Authentication
- curl and TLS/SSL
- Common Tasks with curl
- How to Make a GET Request with curl
- How to Send a POST Request with JSON Data Using curl
- How to View HTTP Response Headers with curl
- How to Debug an HTTP Connection with curl Verbose Mode
- How to Download a File with curl
- How to Check an SSL Certificate with curl
- curl Troubleshooting
- Related Tools and Guides
curl
curl is a command-line tool and library for transferring data with URLs, supporting HTTP, HTTPS, FTP, SCP, SFTP, and dozens of other protocols on Linux, macOS, and Windows.
What curl Does and When to Use It
curl sends requests to URLs and displays the response. System administrators use curl to test HTTP endpoints, debug API responses, download files, inspect SSL certificates, and verify connectivity to remote services. curl supports over 25 protocols, including HTTP/1.1, HTTP/2, HTTP/3, FTP, SFTP, SCP, LDAP, SMTP, and IMAP.
curl differs from wget in scope and design. wget specializes in recursive downloads and mirroring websites. curl focuses on single-request transfers with fine-grained control over headers, authentication, cookies, and TLS settings. curl outputs to stdout by default; wget saves to a file by default.
curl ships pre-installed on macOS and most Linux distributions. For official documentation, see curl.se/docs.
How to Install curl
=== "Ubuntu / Debian"
sudo apt install curl=== "RHEL / CentOS / Fedora"
sudo dnf install curl=== "macOS"
curl ships with macOS. Update via Homebrew:
brew install curlVerify the installed version:
curl --versionCore Concepts of curl
curl Request Methods
curl defaults to GET for HTTP requests. Use
-X (or
--request) to specify a different HTTP method. Common methods: GET (retrieve data), POST (submit data), PUT (replace data), PATCH (partial update), DELETE (remove data). For POST requests, use
-d to send form data or
--json to send JSON.
curl Headers and Output
curl sends and receives HTTP headers alongside the body. Use
-H to add custom request headers. Use
-I (or
--head) to fetch only response headers. Use
-v (verbose) to display the full request/response exchange including TLS handshake details.
curl Authentication
curl supports multiple authentication schemes: basic auth (
-u user:pass), bearer tokens (
-H "Authorization: Bearer TOKEN"), client certificates (
--cert), and OAuth. Use
--netrc to read credentials from
~/.netrc instead of passing them on the command line.
curl and TLS/SSL
curl verifies SSL certificates against the system's CA bundle by default. Use
--cacert to specify a custom CA certificate. Use
-k (or
--insecure) to skip certificate verification — only for debugging, never in production. Use
--cert and
--key for mutual TLS (client certificate authentication).
Common Tasks with curl
How to Make a GET Request with curl
curl sends a GET request and prints the response body to stdout:
curl https://api.example.com/usersHow to Send a POST Request with JSON Data Using curl
curl sends a POST request with a JSON payload using the
--json flag (curl 7.82+) or
-d with a
Content-Type header:
curl --json '{"name":"Alice","email":"alice@example.com"}' https://api.example.com/usersEquivalent command for older curl versions:
curl -X POST -H "Content-Type: application/json" -d '{"name":"Alice"}' https://api.example.com/usersHow to View HTTP Response Headers with curl
curl displays only the response headers with the
-I flag. This sends a HEAD request:
curl -I https://example.comDisplay both headers and body with
-i:
curl -i https://example.comHow to Debug an HTTP Connection with curl Verbose Mode
curl's
-v flag shows the full connection lifecycle — DNS resolution, TCP handshake, TLS negotiation, request headers sent, and response headers received:
curl -v https://example.comHow to Download a File with curl
curl saves the response body to a file with
-o (custom filename) or
-O (original filename from URL):
curl -O https://example.com/archive.tar.gz
curl -o myfile.tar.gz https://example.com/archive.tar.gzResume an interrupted download with
-C -:
curl -C - -O https://example.com/largefile.isoHow to Check an SSL Certificate with curl
curl displays SSL certificate details during a verbose HTTPS request. Combine
-v with
--head to inspect the certificate without downloading the full response:
curl -vI https://example.com 2>&1 | grep -A 6 "Server certificate"curl Troubleshooting
| Error | Cause | Fix |
|---|---|---|
curl: (60) SSL certificate problem: unable to get local issuer certificate | Missing or outdated CA certificate bundle | → Full article |
curl: (7) Failed to connect to host port 443: Connection refused | Remote service is down or port is blocked by firewall | → Full article |
curl: (56) Recv failure: Connection reset by peer | Server or intermediary (firewall, proxy) terminated the connection | → Full article |
curl: (28) Operation timed out | DNS resolution or TCP connection exceeded timeout | → Full article |
curl: (35) SSL connect error | TLS version or cipher mismatch between client and server | → Full article |
Related Tools and Guides
wget is an alternative to curl for downloading files, with recursive download support. See the comparison: curl vs wget: when to use which.
OpenSSL provides lower-level SSL/TLS inspection and certificate management. See the OpenSSL article.