All Posts programming curl cheat-sheet | transfer data from/to a server

curl cheat-sheet | transfer data from/to a server

ยท 268 words ยท 2 minute read

What is curl ? ๐Ÿ”—

Transfers data from or to a server. Supports most protocols, including HTTP, HTTPS, FTP, SCP, etc.

Common commands ๐Ÿ”—

Make an HTTP GET request and dump the contents in the standard output (stdout):

curl https://example.com

Make an HTTP GET request, follow any 3xx redirects, and dump the reply headers and contents to stdout:

curl [-L|--location] [-D|--dump-header] - https://example.com

Download a file, saving the output under the filename indicated by the URL:

curl [-O|--remote-name] https://example.com/filename.zip

Send form-encoded data (POST request of type application/x-www-form-urlencoded). Use --data @file_name or --data @'-' to read from the standard input (stdin):

curl [-X|--request] POST [-d|--data] 'name=bob' http://example.com/form

Send a request with an extra header, using a custom HTTP method and over a proxy (such as BurpSuite), ignoring insecure self-signed certificates:

curl [-k|--insecure] [-x|--proxy] http://127.0.0.1:8080 [-H|--header] 'Authorization: Bearer token' [-X|--request] GET|PUT|POST|DELETE|PATCH|... https://example.com

Send data in JSON format, specifying the appropriate Content-Type header:

curl [-d|--data] '{"name":"bob"}' [-H|--header] 'Content-Type: application/json' http://example.com/users/1234

Pass client certificate and key for a resource, skipping certificate validation:

curl [-E|--cert] client.pem --key key.pem [-k|--insecure] https://example.com

Resolve a hostname to a custom IP address, with verbose output (similar to editing the /etc/hosts file for custom DNS resolution):

curl [-v|--verbose] --resolve example.com:80:127.0.0.1 http://example.com

If you need more information, check out the official manual page: https://curl.se/docs/manpage.html .

I hope you enjoyed reading this post as much as I enjoyed writing it. If you know a person who can benefit from this information, send them a link of this post. If you want to get notified about new posts, follow me on YouTube , Twitter (x) , LinkedIn , and GitHub .