Curl cheatsheet
Curl is an awesome tool. I keep forgetting the switches though, so here's a cheatsheet.
Simple GET request
curl -k "https://localhost/foo?bar=baz&abc=def"JSON POST or PUT request
curl -k -H "Content-Type: application/json" -X POST -d '{"accountName":"test","value":"hello"}' https://localhost/foocurl -X "PUT"... for a PUT
POST a file
curl ... --data-binary @filenameFake a /etc/hosts entry and a Host: header with curl
curl -vvv --resolve 'book.mixu.net:80:123.145.167.189' http://book.mixu.net/Make a request with basic auth enabled
curl -vvv -u name@foo.com:password http://www.example.comor:
curl --user name:password http://www.example.comSet the Referer header
curl -e http://curl.haxx.se daniel.haxx.seSet the User Agent header
curl -A "Mozilla/4.73"or
curl --user-agent "Mozilla".Set Cookies
curl -b "name=Daniel"or
curl --cookie "name=Daniel"Time a request (connect time + time to first byte + total tile)
curl -o /dev/null -w "Connect: %{time_connect} TTFB: %{time_starttransfer} Total time: %{time_total} \n" http://google.comDownloading files from Github
curl -O https://raw.github.com/username/reponame/master/filename