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.
Follow Me:
Top Best Sellers!!