Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

What is the cURL command-line syntax to do a POST request?

How can I make a POST request with the cURL command-line tool?
by

2 Answers

espadacoder11
For a RESTful HTTP POST containing XML:

curl -X POST -d @filename.txt examplewebsite/path/to/resource --header "Content-Type:text/xml"

or for JSON, use this:

curl -X POST -d @filename.txt examplewebsite/path/to/resource --header "Content-Type:application/json"

This will read the contents of the file named filename.txt and send it as the post request.
sandhya6gczb
Data from stdin with -d @-

Example:

echo '{"text": "Hello
world!"}' | curl -d @- any url

Output:

<p>Hello <strong>world</strong>!</p>

Login / Signup to Answer the Question.