How to cURL POST from the Command Line
Curl is the powerful command line utility that allows you to transfer data to or from a server or URL. One common function used by developers is to make a POST request with curl, which is what we’re going to cover here.
We’ll keep things fairly simple and show three examples to make a POST request with curl from the command line, with syntax with and without data, and also to a form.
cURL POST Request Command Line Syntax
You can make a curl POST request with or without data, depending on what you’re attempting to do. Remember that using proper syntax capitalization matters.
curl post request with no data:
curl -X POST http://URL/example.php
curl post request with data:
curl -d "data=example1&data2=example2" http://URL/example.cgi
curl POST to a form:
curl -X POST -F "name=user" -F "password=test" http://URL/example.php
curl POST with a file:
curl -X POST -F "image=@/path/example.gif" http://URL/uploadform.cgi
Similarly, you can also download files with curl too by using a different command string.
curl POST JSON data
curl -H "Content-Type: application/json" -X POST -d '{"user":"bob","pass":"123"}' http://URL/
For further curl specifics or details, refer to the curl manual or help page:
curl --help
curl --manual
Know of a better way to make a post request with cURL? Let us know in the comments. You can also check out some interesting specific uses of the curl command here.
Thx.
Finally got that function app to spin around locally from the command line.
Thank you, I was able to post to a MS Teams channel from the command line using your examples.
Very interesting reading now it will be easier for me to automate sending emails.
Thanks for the article, working a blog backend and this is pretty useful for testing it
this is useful for more curl post request info as well
https://curl.haxx.se/docs/httpscripting.html#POST
Well that was useless. Anyone can list a series of commands. To be useful you need to give some actual examples of how you would use this in context.
Your comment is useless. To be useful you would need to offer some actual information or insight into the topic that is being discussed and how it relates to the context.
curl is probably way over your head, stick with the iPad then you won’t need to get your hands dirty.
Your comment manages to be both useless and also condescending, congratulations! Don’t forget to collect your internet points on the way out.
I totally agree, completely useless.