Skip to content

Instantly share code, notes, and snippets.

@mbodo
Forked from Kartones/CURL-cheatsheet.md
Last active March 16, 2021 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mbodo/eb270bd60f17ef23a49cf5d4a63eaf55 to your computer and use it in GitHub Desktop.
Save mbodo/eb270bd60f17ef23a49cf5d4a63eaf55 to your computer and use it in GitHub Desktop.
CURL Cheatsheet

CURL - cheatsheet

  • XML GET
curl -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET "http://hostname/resource"
  • JSON GET
curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET "http://hostname/resource"
  • JSON PUT
curl -i -H 'Content-Type: application/json' -H 'Accept: application/json' -X PUT -d '{"updated_field1":"updated_value1"}' "http://hostname/resourcex"
  • JSON POST uploading a file
curl -i -H 'Accept: application/json' -X POST -F "filename=@/file/path" -F "other_field=its_value"   "http://hostname/resource"
  • JSON DELETE
curl -i -H 'Content-Type: application/json' -H 'Accept: application/json' -X DELETE -d '{"key1":"value1"}' "http://hostname/resource"
  • GET HTML with authentication
curl -u user:password http://hostname/resource
  • Get only response headers not the content
curl -sSL -D - http://httpbin.org/status/200 -o /dev/null

Useful arguments

  • -k: not check SSL certificates
  • -L: follow redirects
  • -v: get verbose output
  • -V: get headers at output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment