curl Cheatsheet

Last Updated: 2024-01-13

Common options

  • Related to headers:
    • -I: get header only.
    • -H: send with extra header.
  • Often used: -sSL
    • -L follow location change (3XX response code)
    • -S print error
    • -s Silent or quiet mode. Don't show progress meter or error messages.
    • -sS: disable progress meter but still show error messages.
  • Auth
    • -u user:password


Retrieve a page

$ curl www.example.com

Save to a file

$ curl -o example.html www.example.com

Save as the origin name

$ curl -O www.example.com/example.html

Redo the request if page was moved(3XX response code)

$ curl -OL www.example.com/example.html


$ curl -X GET www.example.com


$ curl -X PUT --data-binary @file.xml -H "Content-type: text/xml" http://example.com/put

Use -d(--data) or --data-binary to send data.

-d sends the Content-Type application/x-www-form-urlencoded, to specify another content type, use -H "Content-Type: application/json", e.g.

$ curl -H "Content-Type: application/json" -X POST -d '{"username":"xyz","password":"xyz"}' http://localhost:3000/api/login

Specify Accept header

$ curl -k --header "Accept: application/vnd.oci.image.manifest.v1+json" -u admin:admin https://registry:5000/v2/path/to/manifest

http vs https

If use http:// and an https port

curl localhost:8443 gives an empty reply error. curl -k https://localhost:8443 served the page properly.

$ curl http://google.com:443
curl: (52) Empty reply from server

If use https:// but the server returns a HTTP response

Error message:

http: server gave HTTP response to HTTPS client