Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Last active January 24, 2023 19:15
Show Gist options
  • Save joyrexus/ec24e588af35c64266ab to your computer and use it in GitHub Desktop.
Save joyrexus/ec24e588af35c64266ab to your computer and use it in GitHub Desktop.
POST with curl

Below are a few examples of POSTing form data and file-uploads with curl.

For guidance on when to use which method, see form-data vs -urlencoded.

For details and more examples, see the POST section of the official tutorial.


In the examples below, suppose we need to POST data to https://foo.io/users/joyrexus/shoes, the canonical address for the shoes resource (a "collection" resource, in REST-speak) of a particular user (joyrexus):

URL=https://foo.io/users/joyrexus/shoes

... or, if you want to test your requests, use ...

URL=http://httpbin.org/post

Url-encoded

curl -d "brand=nike" -d "color=red" -d "size=11" $URL

curl --data "brand=nike&color=red&size=11" $URL

Multipart

curl --form "[email protected]" --form "brand=nike" --form "color=red" --form "size=11" $URL

curl -F "[email protected]" -F "brand=nike" -F "color=red" -F "size=11" $URL

Change the name field of a file upload part (nikes.png) by setting filename=NEW_NAME:

curl -F "[email protected];filename=shoes.png" -F "brand=nike" -F "color=red" -F "size=11" $URL

Specify Content-Type by using type=:

curl -F "[email protected];type=image/png" -F "brand=nike" -F "color=red" -F "size=11" $URL

Sans data

curl --data '' $URL

curl -X POST $URL

curl --request POST $URL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment