Comprehensive guide to making POST requests with cURL. Learn how to send JSON payloads, standard URL-encoded form submissions, file uploads with multipart/form-data, and raw binaries.
Frequently Asked Questions
Q1. Do I always need -X POST when using -d?
Technically no. Specifying -d or --data causes cURL to default to the POST method. However, explicitly adding -X POST is considered a best practice for readability in shell scripts.
Q2. How do I send a JSON file from disk using cURL?
Use the @ symbol followed by the path to your file: curl -X POST https://api.example.com/data -H "Content-Type: application/json" -d @payload.json.
Q3. What is the difference between -d and --data-raw in cURL?
-d interprets leading @ symbols as a file path to read from. --data-raw disables this behavior and treats strings starting with @ (like Twitter handles or emails) as literal text.
Q4. How do I URL-encode POST data parameters automatically in cURL?
Use --data-urlencode "param=value with spaces & symbols". cURL will URL-encode the string automatically before transmitting.