Skip to content

curl cheatsheet

Basic usage

GET

GET request

curl http://example.com

Enable compression

curl --compressed http://example.com/

POST

Simple POST data

curl -d name=x http://example.com

Multiple parameters

curl -d name=x -d surname=y http://example.com
curl -d 'name=x&surname=y' http://example.com

Raw data (no special interpretation of @ character)

curl --data-raw "@at" https://example.com

URL-encoded data

curl --data-urlencode name=val http://example.com

Binary data

curl --data-binary @filename https://example.com

JSON

curl --json '{"foo": "bar"}' https://example.com/

Chunked encoding

curl -H "Transfer-Encoding: chunked" -d @file http://example.com

Send output of the command in POST request

uname -a | curl -XPOST -d @- http://example.com

HEAD request

curl -I http://example.com

PUT

curl -T localfile http://example.com/new/resource

Save output to the file

Write output to the file

curl -o file.html http://example.com

Write output to the file, use remote file name

curl -O http://example.com/file.html

Do not overwrite existing files

curl --no-clobber https://example.com/image -o file.png

Skip TLS certificate validation

curl -k https://example.com

Silent output

curl -s http://example.com

Fail fast with no output at all on server errors

curl -f http://example.com

Do not handle sequences of /../ and /./ in the URL.

curl --path-as-is http://example.com/../../etc/passwd

Proxy

Connect via proxy

curl -x http://127.0.0.1:8080 http://example.com

Socks 4a

curl --socks4a hostname:1080 https://example.com

Socks5 proxy

curl --socks5 proxy.example:1080 https://example.com

Set username and password for proxy authentication

curl --proxy-user username:pass -x http://127.0.0.1:8080 https://example.com

Set HTTP headers

Set Cookie value

curl -b cookie=value https://example.com

Set User-Agent

curl -A "New User Agent" https://example.com

Set referer

curl -e "https://test.example" https://example.com

Set header

curl -H "User-Agent: Hello" https://example.com
curl -H 'X-Custom-Header: HeaderValue' https://example.com

Set Content-Type

curl -d '{}' -H 'Content-Type: application/json' https://example.com

Send a file

Send file as form

curl -F "file=@/path/to/file" http://example.com
curl -F "x=`cat /path/to/file`" http://example.com
cat /path/to/file | curl -F ":data=@-" http://example.com

Upload file

curl -T /path/to/file http://example.com

Send in POST body

curl -XPOST -d @/path/to/file http://example.com

Send binary data in POST body

curl --data-binary @binary.data https://example.com

FTP

Send file via FTP

curl -T /path/to/file ftp://server -u user:password

References