Tired of guessing why your API calls keep failing? A cURL POST request is the fastest way to test endpoints and send data straight away from your command line. This guide shows you how to handle this. From JSON, form data, file uploads, authentication, and headers with real-world examples. By the end of this cURL Post guide, you’ll know the exact flags to use, how to debug errors, and where cURL fits into everyday API testing and automation.
Table of Contents
- Introduction: Why Use cURL for POST Requests
- Basic Syntax of a cURL POST Request
- Sending Data with -d (application/x-www-form-urlencoded)
- Posting JSON Data
- Working with Files and Form Data
- Adding Custom Headers
- Authentication with cURL POST
- Common Use Cases & Examples
- Troubleshooting & Best Practices
- Conclusion & Quick Reference Cheat Sheet
- FAQ: cURL POST

⚠️ Content Disclaimer: This article is intended for educational and informational purposes only. The examples provided, including commands, URLs, headers, and credentials, are simplified demonstrations meant to show how cURL POST requests work. Readers should avoid sending sensitive data such as passwords, tokens, or personal information to public endpoints like httpbin.org. Security practices, including API key management, SSL/TLS handling, and authentication methods, can vary depending on your system and provider. For that reason, you should always consult official API documentation and follow established security best practices before applying these commands in a production environment.
1. Introduction: Why Use cURL for POST Requests
If you are here, it is because you might have tinkered with APIs. If you did, there are high chances you’ve run into cURL. It’s a tiny but mighty tool that lives inside most operating systems. With cURL, you can send HTTP requests straight from your command line. That means you don’t need a browser and no fancy GUI (just raw control.)
One of the most common tasks? Sending a cURL POST request.
POST requests are a big deal because they let you do more than just “ask” a server for info (that’s what GET is for). With POST, you’re actually sending data: logging in, uploading a file, posting a form, or testing an API endpoint.

So, once you get the hang of cURL POST requests, you’ll wonder how you ever debugged APIs without it.
Let’s start simple.
2. Basic Syntax of a cURL POST Request
At its simplest, a POST request with cURL looks like this:
|
1 2 3 |
curl -X POST <url> -d "param1=value1¶m2=value2" |
Let’s break it down:
- curl → the command itself.
- -X POST → tells cURL to use the POST method.
- <url> → the endpoint you’re hitting.
- -d → stands for “data,” the body of your request.
| 👉 Small but important detail: if you don’t use -X POST but you do use -d, cURL will automatically switch to POST. That’s why many people skip -X POST unless they want to be extra clear. |
Minimal working example:
|
1 2 3 |
curl -d "name=Alex&age=30" https://httpbin.org/post |
This sends data to https://httpbin.org/post, and you’ll see a JSON response echoing back what you sent.
3. Sending Data with -d (application/x-www-form-urlencoded)
By default, cURL uses application/x-www-form-urlencoded when you send data with -d.
Think of it as how old-school HTML forms worked.
Example:
|
1 2 3 |
curl -d "username=testuser&password=12345" https://httpbin.org/post |
The server receives this as if you submitted a web form.
⚠️ Common mistake: forgetting quotes around your data. If you write:
|
1 2 3 |
curl -d username=testuser&password=12345 https://httpbin.org/post |
…the & gets interpreted by your shell, and things break. Always wrap your data in quotes.
4. Posting JSON Data
These days, APIs usually expect JSON, not form-encoded data. To send JSON, you need to set the correct Content-Type header and pass your data as a JSON string.
Basic JSON POST:
|
1 2 3 4 5 |
curl -X POST https://httpbin.org/post \ -H "Content-Type: application/json" \ -d '{"name": "Sarah", "age": 25}' |
Notice two things:
- We added -H “Content-Type: application/json”.
- Our data is inside single quotes, with JSON inside.
Posting nested JSON:
|
1 2 3 4 5 |
curl -X POST https://httpbin.org/post \ -H "Content-Type: application/json" \ -d '{"user": {"id": 42, "name": "Alex"}, "active": true}' |
Posting JSON from a file:
If you have a file named data.json, you can post it directly:
|
1 2 3 4 5 |
curl -X POST https://httpbin.org/post \ -H "Content-Type: application/json" \ -d @data.json |
That @ tells cURL to read the file contents instead of treating it as a string.
Faster POST requests ⚡
Combine cURL POST with stable rotating proxies for reliable, high-speed testing.
Try fast proxies5. Working with Files and Form Data
Sometimes you’re not just sending JSON—you’re uploading files or simulating form submissions.
That’s where -F comes in.
Upload a file:
|
1 2 3 4 |
Upload a file with extra fields:
|
1 2 3 4 5 |
Here’s the difference:
- -d → sends data as raw body (application/x-www-form-urlencoded).
- -F → sends multipart form data (multipart/form-data), which is needed for files.
6. Adding Custom Headers
Sometimes servers want more than just data. They need headers: tokens, content types, cookies.
Setting headers with -H:
|
1 2 3 4 5 6 |
curl -X POST https://httpbin.org/post \ -H "Content-Type: application/json" \ -H "X-App-Version: 1.2.3" \ -d '{"status": "ok"}' |
Authentication with API key:
|
1 2 3 |
curl -X POST https://api.example.com/data \ -H "Authorization: Bearer YOUR_API_KEY" \ -d '{"data": "sample"}' |
Cookies:
|
1 2 3 4 5 |
curl -X POST https://example.com/login \ -H "Cookie: sessionid=abcd1234" \ -d "user=tom&pass=secret" |
| ⚠️ Security tip: don’t paste your real tokens or passwords into shared scripts or Git repos. |
7. Authentication with cURL POST
There are multiple ways to authenticate with cURL.
1. Basic Auth (username + password)
|
1 2 3 |
curl -u "user:password" -X POST https://httpbin.org/post |
2. Token-based Auth
|
1 2 3 |
curl -u "user:password" -X POST https://httpbin.org/post |
3. OAuth (token exchange)
OAuth can be more complex, but the principle is the same: you pass tokens as headers. Many APIs provide curl-ready snippets in their docs.
8. Common Use Cases & Examples
Linux / Mac
|
1 2 3 |
curl -d "name=Mike" https://httpbin.org/post |
Windows CMD
Windows needs extra care with quotes. Use double quotes around the data:
|
1 2 3 |
curl -d "name=Mike" https://httpbin.org/post |
…but escape inner quotes if you’re posting JSON:
|
1 2 3 4 |
curl -H "Content-Type: application/json" \ -d "{\"name\":\"Mike\"}" https://httpbin.org/post |
Using a Proxy
|
1 2 3 4 |
curl -x http://proxy.example.com:8080 \ -d "param=value" https://httpbin.org/post |
Learn more about this topic in: cURL Proxy: A Beginner’s Guide
Hitting Dummy APIs
https://httpbin.org/post is a lifesaver for testing. It simply echoes your request back so you can see what’s going on.
9. Troubleshooting & Best Practices
Even seasoned developers hit roadblocks with cURL. Here are some fixes:
- Missing quotes → always wrap -d data in quotes.
- Wrong headers → check if the API expects application/json vs application/x-www-form-urlencoded.
- SSL/TLS issues → try adding -k (not recommended for production, but fine for testing).
- Silent failures → add -v to see request/response details:
|
1 2 3 |
curl -v -d "test=data" https://httpbin.org/post |
Debug tip: If things still look off, try –trace-ascii debug.txt to log the full conversation.
10. Conclusion & Quick Reference Cheat Sheet
By now, you’ve seen how flexible cURL POST requests can be. Whether you’re sending form data, JSON, or uploading files, cURL gives you full control from the command line.
Here’s a quick cheat sheet for the road:
| Flag | Meaning | Example |
| -d | Send data (form-encoded) | -d “user=alex&pass=123” |
| -F | Send multipart form data (files) | -F “[email protected]” |
| -H | Add custom header | -H “Content-Type: application/json” |
| -X POST | Force POST method | -X POST <url> |
| -u | Basic auth | -u user:pass |
| –proxy | Use a proxy | –proxy http://host:port |
| -v | Verbose/debug output | -v |
Next time you’re testing an endpoint, instead of writing a full script, fire off a quick curl POST example. Bookmark this guide—you’ll be back for it when your next API acts up.
11. FAQ: cURL POST
On most Linux and macOS systems, yes — cURL is included out-of-the-box. Windows 10 and later versions also ship with cURL preinstalled. If you get a “curl: command not found” error, you’ll need to install it manually via your package manager (e.g., apt, yum, brew) or download it from curl.se.
Absolutely. Developers often embed cURL commands in shell scripts (.sh files) or batch scripts (.bat on Windows) to automate API testing, authentication, or file transfers. Just remember to escape special characters (quotes, ampersands) differently depending on your shell. Learn more about this topic in A Guide to Python cURL
Add the -v or –verbose flag to see the full request/response exchange. For even more detail, use –trace or –trace-ascii followed by a filename. This helps diagnose issues with headers, redirects, SSL/TLS, or request formatting.
Yes, cURL fully supports HTTPS/TLS connections. You may need to add -k or –insecure if the server uses a self-signed certificate (not recommended in production). You can also specify certificates and keys for mutual TLS authentication.
Not in a single command. However, you can chain multiple requests in a script or use –next to separate different requests in the same execution. For performance-heavy needs, consider wrapping cURL inside a tool like xargs or a dedicated HTTP client library.
What’s possible with POST? 🧭
Push cURL POST requests further by routing them through rotating residential proxies.
See options
0Comments