cURL snippets

Page content

Send a POST request

curl -X POST https://yourdomain.com -d @data.txt

@ is necessary.

Enable redirecting

curl -L yourdomain.com

Ignore TLS certificate error in cURL

Frequently used in test environment.

curl --insecure https://yourdomain.com
# or
curl -k https://yourdomain.com

Download a content which includes redirect

curl -L yourdomain.com --output myfilename

IPv6

Force curl to DNS as IPv6.

curl -6 mydomain.com
# From man
# -6, --ipv6          Resolve names to IPv6 addresses

Show header only

curl -sS -I https://youdomain.com

-s: = --silent -S: = --show-error -I: = --head

Name resolve

When my local server domain is mydomain.com, I test like,

curl https://mydomain.com --resolve mydomain.com:443:127.0.0.1

Send GraphQL request

curl -g \
    -X POST \
    -H "Content-Type: application/json" \
    -d '{"query":"query{somethihg(thisisparam: \"foo\"){field1 field2{subfield1 subfield2(subsubfield1)}}}"}' \
    https://my-graphql-endpoint.com