Skip to content

Instantly share code, notes, and snippets.

@ramingar
Last active September 20, 2016 07:34
Show Gist options
  • Select an option

  • Save ramingar/3e9969e3ea6ffb20eb37 to your computer and use it in GitHub Desktop.

Select an option

Save ramingar/3e9969e3ea6ffb20eb37 to your computer and use it in GitHub Desktop.
curl command #curl #commandline #commands

Without data:

curl --data '' https://example.com/resource.cgi
curl -X POST https://example.com/resource.cgi
curl --request POST https://example.com/resource.cgi

With fields:

curl --data "param1=value1&param2=value2" https://example.com/resource.cgi
curl -i 'http://midominio.com/api/auth' -H 'Content-Type: application/hal+json' --data '{"_username": "miusername", "_password": "mipassword"}' -X POST

Multipart:

curl --form "fileupload=@my-file.txt" https://example.com/resource.cgi
curl -i 'http://midominio.com/api/survey/705/main-image' -H 'Content-Type: multipart/form-data' -H 'Token:xxxxxxxxxxxxxxxxxxxxxx' -F "image=@/ruta/a/mi/imagen.jpg" --compress

Multipart with fields and a filename:

curl --form "fileupload=@my-file.txt;filename=desired-filename.txt" --form param1=value1 --form param2=value2 https://example.com/resource.cgi

For large files, consider adding parameters to show upload progress: (The -o output is required, otherwise no progress bar will appear).

curl --tr-encoding -X POST -v -# -o output -T filename.dat \ http://example.com/resource.cgi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment