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.
Facing issues? Have Questions? Post them here! I am happy to answer!
- cURL Option to show HTTP Response Status Code
- URL Encode cURL HTTP GET\POST Data with Examples
- Capture cURL Request Output to a File
- Fix: Curl No Match Found Error
- trurl: A new command-line tool for URL parsing and manipulation by cURL Developer
- Send JSON Data as Payload using cURL HTTP POST Request
- cURL: Show Request and Response Headers
- Get cURL command from Chrome Inspect Network HTTP URL
- Save cURL Command Output to a external file
- cURL DELETE Request with Examples
- How to URL Encode Data for a cURL Request Parameters
- cURL Example using IP (IPv4 and IPv6) address and Port
- How to convert a Postman request to cURL Command
- [fix] command not found curl
- How to Pretty Print cURL JSON Output in Terminal
- How to follow redirects in cURL Command Request
- How to pass authorization header using cURL
- cURL -x Use of HTTP Proxy Server Examples
- Downloading Google Chrome using cURL Command
- How to get cURL Command to run in verbose mode?
- List of 28 Protocols supported by cURL with Examples
- Hide cURL Outputs and Errors on Terminal
- cURL -d Option with Examples
- How to show SSL Certificate details using cURL Command
- Perform Basic Authentication using cURL with Examples
- 18: Get Sub List By Slicing a Python List - 1000+ Python Programs - Python-Programs
- Create Custom Toast Android Programming - Android
- Hide Scrollbar from Android Views - Android
- WhatsApp Web escanner - WhatsApp
- How to locate Python Installation on Windows (10/11) - Windows
- Java SE JDBC Select Statement Example - Java
- How to refresh Safari on Mac (macOS) using keyboard shortcut - MacOS
- How to ls command to output one entry per line [macOS/Linux/Bash] - Linux