The command
curl -d "name=Ada&role=admin" https://httpbin.org/post
Opens the request console with this request filled in. It is sent from api-tester.com's server rather than from your machine, so it shows what the endpoint returns, not how your own network or curl build behaves.
What the flags do
| Flag | What it does |
|---|---|
-d data | Body sent as-is with Content-Type: application/x-www-form-urlencoded. |
--json data | Body plus JSON Content-Type and Accept headers (curl 7.82+). |
-F name=value | A multipart/form-data body, the kind file uploads use. |
--data-binary @file | A file sent byte for byte, newlines included. |
-X POST | Forces the method name. Only needed for a POST with no body at all. |
Four ways to send a POST body
The request body and its Content-Type have to agree, because the server chooses a parser from the header. Curl sets a matching header for three of these four forms; with --data-binary it still claims form encoding unless you say otherwise.
# 1. form fields (the default)
curl -d "name=Ada&role=admin" https://httpbin.org/post
# 2. JSON
curl --json '{"name":"Ada","role":"admin"}' https://httpbin.org/post
# 3. multipart, as an HTML form with a file input would send
curl -F "name=Ada" -F "avatar=@photo.png" https://httpbin.org/post
# 4. a raw file, with the type stated explicitly
curl --data-binary @report.csv -H "Content-Type: text/csv" https://httpbin.org/post
A POST without a body
Some endpoints want a POST that carries nothing: triggering a job, rotating a key. Here -X POST is the right tool, but add an explicit empty body so curl sends Content-Length: 0. Several servers and proxies reject a bodiless POST that lacks it with 411 Length Required.
curl -X POST -d "" https://httpbin.org/post
Common mistakes
- JSON sent with plain
-dis labelled as a form. Add-H "Content-Type: application/json"or use--json, or expect415or an empty parsed body. -d @filestrips newlines. Use--data-binaryfor anything where line breaks matter.- After a 301 or 302, curl -L repeats the request as a GET, dropping the body. That is standard browser behaviour, not a bug; see the redirect example.
Related curl examples
Curl POST Body Example
The body of a POST can come from four places: the command line, a file, another program's output, or a block of text in your script.
Curl POST JSON Example
Sending JSON takes two things: the JSON itself and a header saying that is what it is.
Curl POST Form Example
HTML forms post in one of two encodings, and curl has a flag for each.
Curl -d Flag Example
-d looks like "send this data", but it does three things at once and quietly edits file input.
All Curl Examples
49 worked examples, grouped by what you are trying to do.
More under Methods
References
- curl man page: -d — How -d builds a request body and switches the method to POST.
- MDN: POST — The method's semantics, including when it is and is not safe to repeat.
These links leave api-tester.com, which is independent of the projects they point to.
FAQ
How do I make a POST request with curl?
Pass a body with -d, for example curl -d "name=Ada" https://httpbin.org/post. Supplying data makes curl use POST automatically.
Do I need -X POST with curl?
No, not when you send data with -d, --json or -F. Use -X POST only for a POST that has no body.
What Content-Type does curl use for POST?
application/x-www-form-urlencoded for -d and --data-binary, application/json for --json, and multipart/form-data with a generated boundary for -F.