In order to send data via an HTTP POST request in cURL, you need to make use of the -d or the --data option.
From cURL manual/help page:
-d, --data <data> HTTP POST data
separating &-symbol. Thus, using '-d name=daniel -d skill=lousy'
curl -d "name=curl" https://example.com
curl -d "name=curl" -d "tool=cmdline" https://example.com
curl -d @filename https://example.com
Example 1: Sending Login Form Details using -d option
curl -X POST -d "userid=EMP101&password=thepassword" https://code2care.org/employee/login
As you can see, we have provided the form data with -d flag and passing the userid and password details as key-value pairs like a query string.
If you want you can send the form body data parameters as separate key and value pairs, you can do it as follows,
curl -X POST -d "userid=EMP101" -d "password=thepassword" https://code2care.org/employee/login
Example 2: Sending JSON data to REST API POST Request
curl -X POST --data '{"product_id": 1010, "search_query": "iPhone 15", "user_id":"EMP101"}'
-H "Content-Type: application/json"
https://code2care.org/api/product-details/
curl -X POST --data '{"product_id": 1010, "search_query": "iPhone 15", "user_id":"EMP101"}'
-H "Content-Type: application/json"
https://code2care.org/api/product-details/
In the above example, we are sending the JSON data to an HTTP POST REST API using the --data option.
Note: We have to set the Content-Type header as application/json in this case.
Example 3: Sending Data from a file using -d option
curl -X POST -d "@upload-batch_2023-07-01.csv" https://code2care.org/financial-data/upload-job/
As you can see in the above example we are reading the data from a file and using cURL to upload its content to a POST API Request.

Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!