cURL Commands

Essential cURL commands for HTTP requests and API testing.

cURL Commands

Essential cURL commands for HTTP requests and API testing

Basic Requests

curl <url>

Simple GET request

curl https://api.example.com/users
curl -X POST <url>

POST request

curl -X POST https://api.example.com/users
curl -X PUT <url>

PUT request

curl -X PUT https://api.example.com/users/1
curl -X DELETE <url>

DELETE request

curl -X DELETE https://api.example.com/users/1
curl -I <url>

Fetch headers only

curl -I https://example.com

Headers & Authentication

curl -H "Header: Value" <url>

Add custom header

curl -H "Content-Type: application/json" https://api.example.com
curl -H "Authorization: Bearer <token>" <url>

Bearer token authentication

curl -H "Authorization: Bearer abc123" https://api.example.com/protected
curl -u user:password <url>

Basic authentication

curl -u admin:secret123 https://api.example.com/admin
curl -A "User-Agent" <url>

Set custom user agent

curl -A "Mozilla/5.0" https://example.com

Request Body

curl -d "data" <url>

Send form data

curl -d "name=John&email=john@example.com" https://api.example.com/users
curl -d @file.json <url>

Send data from file

curl -d @user.json https://api.example.com/users
curl --data-raw '{"key":"value"}' <url>

Send raw JSON data

curl --data-raw '{"name":"John"}' -H "Content-Type: application/json" https://api.example.com/users
curl -F "file=@path" <url>

Upload file (multipart)

curl -F "file=@photo.jpg" https://api.example.com/upload

Output & Response

curl -o file <url>

Save response to file

curl -o response.json https://api.example.com/data
curl -O <url>

Save with remote filename

curl -O https://example.com/file.zip
curl -i <url>

Include response headers

curl -i https://api.example.com/status
curl -v <url>

Verbose mode (debug)

curl -v https://api.example.com
curl -s <url>

Silent mode (no progress)

curl -s https://api.example.com/data
curl -w "%{http_code}" <url>

Print HTTP status code

curl -w "%{http_code}" https://api.example.com

Advanced Options

curl -L <url>

Follow redirects

curl -L https://short.url/abc123
curl -k <url>

Ignore SSL certificate errors

curl -k https://self-signed.example.com
curl --max-time <seconds> <url>

Set timeout

curl --max-time 30 https://slow-api.example.com
curl -x proxy:port <url>

Use proxy

curl -x http://proxy.example.com:8080 https://api.example.com
curl -b cookies.txt <url>

Send cookies from file

curl -b cookies.txt https://example.com
curl -c cookies.txt <url>

Save cookies to file

curl -c cookies.txt https://example.com/login