Skip to the content.

curl

GET

curl --connect-timeout 3.5 <url>

# querystring: ?q=python&count=20&comment=hello%20world
curl -G -d 'q=python' -d 'count=20' --data-urlencode 'comment=hello world' <url>

POST

JSON

curl --json @<data.json> -X POST <url>
curl --json @- -X POST <url> < data.json

automatically set the following headers:

Content-Type: application/json

Form

-d 'param1=val1&param2=val2'
-d 'param1=val1' -d 'param2=val2'
--data-urlencode 'comment=hello world'

automatically set the following headers:

Content-Type: application/x-www-form-urlencoded
-H 'Accept: application/json'
--header 'Accept: application/json'

Upload

curl -X PUT --upload-file <file.png>
-F 'fileparam=@<file.png>;filename=<target.png>'

automatically set the following headers:

Content-Type: multipart/form-data
-F 'fileparam=@<file.png>;type=image/png;filename=<target.png>'

automatically set the following headers:

Content-Type: application/octet-stream

User Agent

# = -H 'User-Agent: curl/7.1'
-A 'curl/7.1'
-b <cookie-file> or 'key=val;key2=val2'
--cookie <cookie-file> or 'key=val;key2=val2'

-c <cookie-file>
--cookie-jar <cookie-file>

Range

-r 0-1024

See HTTP Range - Linux Cookbook.

Referer

# = -H 'Referer: https://google.com?q=example'
-e 'https://google.com?q=example'

Redirect (3XX)

-L

Proxy

-x http://proxy
--proxy http://proxy

Bypass Server TLS/SSL certificate verification

-k

Transfer-Encoding: chunked

--chunked
Transfer-Encoding: chunked

Download

curl -C - -L --parallel --parallel-max 100 --max-time 30 --retry 3 -o <download-file> <url>

Speed Limit

--limit-rate 10K

HTTP Version

# Since 7.47.0, the curl tool enables HTTP/2 by default for HTTPS connections.
# `--http3`: experimental
--http1.1
--http2
--http3

TCP Keep-Alive

--keepalive-time 15

Multiple Transfers With A Single Command Line

-O <url1> -O <url2>

TCP Fast Open

curl --tcp-fastopen <url>

API

References