Mastering curl: Essential Command-Line Options for HTTP Requests

curl is a versatile command-line utility for interacting with web servers using URLs. Its name stands for "Client URL," and it supports numerous protocols including HTTP, HTTPS, FTP, and more. With dozens of options, curl can replace GUI-based tools like Postman when used proficiently.

This guide covers the most practical curl flags for everyday use, distilled from authoritative references such as the curl Cookbook.

Basic GET Request

By default, curl performs a GET request:

$ curl https://www.example.com

User-Agent Customization (-A)

The -A flag sets the User-Agent header:

$ curl -A 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36' https://example.com

To omit the header entirely:

$ curl -A '' https://example.com

Alternatively, use -H to define it explicitly:

$ curl -H 'User-Agent: MyApp/1.0' https://example.com

Cookie Handling

Send cookies with -b:

$ curl -b 'sessionid=abc123' https://example.com
$ curl -b 'pref=dark;lang=en' https://example.com
$ curl -b saved_cookies.txt https://example.com

Save received cookies to a file using -c:

$ curl -c saved_cookies.txt https://example.com

POST Data (-d)

Send form data via POST:

$ curl -d 'username=alice&token=xyz' https://api.example.com/auth

Multipart form fields or multiple -d flags are supported. To read data from a file:

$ curl -d '@payload.json' https://api.example.com/upload

For automatic URL encoding, use --data-urlencode:

$ curl --data-urlencode 'query=hello world' https://search.example.com

Referer Header (-e)

Set the Referer header:

$ curl -e 'https://referrer.com/page' https://target.example.com

Equivalent using -H:

$ curl -H 'Referer: https://referrer.com/page' https://target.example.com

File Uploads (-F)

Upload files as multipart form data:

$ curl -F 'avatar=@profile.jpg' https://upload.example.com

Specify MIME type and filename:

$ curl -F 'file=@document.pdf;type=application/pdf;filename=resume.pdf' https://upload.example.com

GET with Query Parameters (-G)

Convert -d data into URL query parameters:

$ curl -G -d 'q=cats' -d 'size=large' https://api.example.com/images

This results in a GET request to https://api.example.com/images?q=cats&size=large.

Custom Headers (-H)

Add arbitrary headers:

$ curl -H 'Accept: application/json' -H 'X-API-Key: secret123' https://api.example.com/data

Commonly used with JSON payloads:

$ curl -d '{"email":"user@example.com"}' -H 'Content-Type: application/json' https://api.example.com/subscribe

Response Headers

Show response headers along with body (-i):

$ curl -i https://example.com

Fetch only headers via HEAD request (-I or --head):

$ curl -I https://example.com

Security and Redirection

Skip SSL certificate verification (-k):

$ curl -k https://self-signed.badssl.com

Follow HTTP redirects automatically (-L):

$ curl -L https://short.url/abc

Bandwidth Throttling

Limit trensfer speed (--limit-rate):

$ curl --limit-rate 100K https://large-file.example.com/data.zip

Output Control

Save response to a specific file (-o):

$ curl -o homepage.html https://example.com

Save using the remote filename (-O):

$ curl -O https://example.com/files/report.pdf

Quiet and Silent Modes

Suppress progress meter and errors (-s):

$ curl -s https://example.com > output.html

Show errors only when combined with -S:

$ curl -sS https://example.com

Discard all output:

$ curl -s -o /dev/null https://example.com

Authentication (-u)

Provide credentials for Basic Auth:

$ curl -u 'admin:securepass' https://admin.example.com

Username-only prompts for password:

$ curl -u 'admin' https://admin.example.com

Credentials can also be embedded in the URL:

$ curl https://admin:securepass@admin.example.com

Debugging (-v, --trace)

Verbose output shows request/response details:

$ curl -v https://example.com

For raw protocol tracing (including binary data):

$ curl --trace - https://example.com

Proxy Configuration (-x)

Route requests through a proxy:

$ curl -x http://proxy.local:3128 https://example.com
$ curl -x socks5://user:pass@proxy.local:1080 https://example.com

If no protocol is specified, HTTP is assumed.

Custom HTTP Methods (-X)

Override the request method:

$ curl -X DELETE https://api.example.com/resource/123
$ curl -X PUT -d '{"status":"active"}' https://api.example.com/update

Tags: curl HTTP CLI REST API web development

Posted on Thu, 28 May 2026 23:15:59 +0000 by n3ightjay