Use cURL for POST requests when you need a fast way to test APIs, send form data, or debug a webhook without opening a full API client; curl supports many protocols and features made for command line HTTP work [source: curl]. It is small, scriptable, and already installed on many macOS and Linux systems.
TLDR: The three most practical ways to send POST requests with cURL are form posts, JSON body posts, and file uploads. For example, curl -X POST -d "email=sam@example.com" https://api.example.com/signup sends a basic form request in seconds. In a small support workflow, a team could test 50 signup records in one afternoon without building a custom app. That saves time when an API fails and everyone wants proof, not guesses.
1. Send a Simple Form POST
The easiest POST request in cURL uses -d, short for data. This sends data as application/x-www-form-urlencoded, which is the same style many classic HTML forms use.
curl -X POST https://api.example.com/login \
-d "username=alex" \
-d "password=secret123"
This is handy for login forms, newsletter signups, contact forms, and test endpoints. You can pass each field with its own -d flag. cURL joins them together for you.
What happens here?
-X POSTtells cURL to use the POST method.-dadds body data to the request.- cURL sets the content type to form data by default.
Honestly, it feels like half of API debugging is just finding out whether the server wanted form data or JSON. This version answers that fast.
2. Send a JSON POST Request
Most modern APIs expect JSON. That means you need to send a raw JSON body and set the right header. If you skip the header, the server may reject the request or read it in the wrong way. Annoying, yes. Common, also yes.
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name":"Maya","email":"maya@example.com","role":"editor"}'
This style is perfect for testing REST APIs. You can create users, send orders, update settings, or trigger events.
If your JSON is longer, put it in a file. This is cleaner and avoids broken quotes in your terminal.
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d @user.json
Your user.json file might look like this:
{
"name": "Maya",
"email": "maya@example.com",
"role": "editor"
}
This approach is easier to reuse. It also works well in scripts. You can keep sample payloads in a folder and run them again when a bug returns.
Quick tip: Add -i if you want to see response headers too.
curl -i -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d @user.json
That helps when checking status codes, cookies, rate limits, or auth problems. Expect to waste time on missing headers at least once. A single bad header can add 20 minutes of pointless guessing.
3. Upload a File With POST
Some POST requests need to send files. Think profile photos, PDFs, CSV imports, logs, or product images. For this, use -F. It sends data as multipart/form-data, which is the usual format for uploads.
curl -X POST https://api.example.com/upload \
-F "file=@report.pdf" \
-F "user_id=42"
The @ sign tells cURL to read the file from your computer. The second field sends normal text data along with it.
You can also set a custom filename:
curl -X POST https://api.example.com/upload \
-F "file=@report.pdf;filename=monthly-report.pdf"
This is useful when the server saves uploaded files by name. It also helps when testing systems that check file names, not just file content.
Add Authentication When Needed
Many POST requests need a token. Add it with -H:
curl -X POST https://api.example.com/orders \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"product_id":1001,"quantity":2}'
Keep tokens out of shared screenshots and public logs. It drives me crazy that so many bug reports still include live keys. Treat them like passwords.
Useful Flags for Better POST Testing
-v: shows detailed request and response info.-i: includes response headers in the output.-s: silent mode, useful in scripts.-o file.txt: saves the response to a file.-w "%{http_code}": prints the HTTP status code.
Here is a clean script-friendly example:
curl -s -o response.json -w "%{http_code}" \
-X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d @user.json
This saves the response and prints the status code. It is great for checks in shell scripts or simple deployment tests.
Which Method Should You Use?
- Use
-dwith plain fields for basic forms. - Use
-H "Content-Type: application/json"plus-dfor JSON APIs. - Use
-Ffor file uploads and multipart forms.
cURL is not fancy, and that is part of the charm. It gives you a direct way to ask, “What did the server actually receive?” When a POST request breaks, that simple question is often the fastest path to the fix.