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
curl -d "brand=nike" -d "color=red" -d "size=11" $URL
curl --data "brand=nike&color=red&size=11" $URL
curl --form "image=@nikes.png" --form "brand=nike" --form "color=red" --form "size=11" $URL
curl -F "image=@nikes.png" -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 "image=@nikes.png;filename=shoes.png" -F "brand=nike" -F "color=red" -F "size=11" $URL
Specify Content-Type
by using type=
:
curl -F "image=@nikes.png;type=image/png" -F "brand=nike" -F "color=red" -F "size=11" $URL
curl --data '' $URL
curl -X POST $URL
curl --request POST $URL