# curl POST Request: JSON, Form Data and Files

> Send a POST request with curl: -d for form data, --json for JSON, -F for files, with real output, Windows quoting fixes, redirects and POST through a proxy.

[Home](https://quanticdata.io/) / [Blog](https://quanticdata.io/blog/) / curl POST Request: JSON, Form Data and Files

# curl POST request: JSON body, form data, files and Windows quoting

Proxies · Nov 20, 2026 · 5 min read · By [Aldo Morese](https://quanticdata.io/about/), founder of QuanticData

![Three ways to send a curl POST request and the Content-Type each one sends: -d with name=Ada sends application/x-www-form-urlencoded, --json sends application/json with Accept application/json, -F with file=@rows.csv sends multipart/form-data; the card notes that in Windows PowerShell 5.1 a JSON body needs escaped quotes or @file.](https://quanticdata.io/blog/curl-post-request/hero.webp?v=20261120h)

On this page

- [The three kinds of POST body](https://quanticdata.io/blog/curl-post-request/#the-three-kinds-of-post-body)
- [POST form data with -d](https://quanticdata.io/blog/curl-post-request/#post-form-data-with-d)
- [POST JSON: --json, or -H plus -d](https://quanticdata.io/blog/curl-post-request/#post-json-json-or-h-plus-d)
- [POST JSON from Windows PowerShell and cmd](https://quanticdata.io/blog/curl-post-request/#post-json-from-windows-powershell-and-cmd)
- [Upload a file with -F](https://quanticdata.io/blog/curl-post-request/#upload-a-file-with-f)
- [Status code, errors and redirects](https://quanticdata.io/blog/curl-post-request/#status-code-errors-and-redirects)
- [POST through a proxy](https://quanticdata.io/blog/curl-post-request/#post-through-a-proxy)
- [Which network for POST jobs](https://quanticdata.io/blog/curl-post-request/#which-network-for-post-jobs)

To send a POST request with curl, add a body: `curl -d "name=Ada" URL` posts form data, `curl --json '{"name":"Ada"}' URL` posts JSON with the right headers, and `curl -F "file=@rows.csv" URL` uploads a file. Each one switches curl to POST, so `-X POST` is not needed.

**Run it on the free credit.** Every QuanticData account gets $2 of free API usage per month.

[Start free — $2/month included](https://quanticdata.io/signup/?utm_source=blog&utm_medium=website&utm_campaign=blog-lead&utm_content=curl-post-request) · [Explore Residential Proxies from $0.80/GB](https://quanticdata.io/residential-proxies/)

We sent every request below to httpbin.org/post, which echoes back what it received, on 20 November 2026 with curl 8.22.0 on Windows 11, directly and through QuanticData proxies. The output is real; exit IPs are masked and the trace header httpbin adds is left out.

## The three kinds of POST body

| Option | Body sent | Content-Type curl sets | Use it for |
| --- | --- | --- | --- |
| `-d "name=Ada&lang=en"` | `name=Ada&lang=en` (16 bytes) | application/x-www-form-urlencoded | HTML forms, simple APIs |
| `--json '{"name":"Ada"}'` | the JSON text (14 bytes) | application/json, plus Accept: application/json | JSON APIs |
| `-F "file=@rows.csv" -F "note=test"` | multipart parts | multipart/form-data; boundary=... | File uploads |
| `--data-urlencode "q=a&b c"` | `q=a%26b%20c`, decoded by the server as `a&b c` | application/x-www-form-urlencoded | Values with &, spaces or = |

## POST form data with -d

```bash
$ curl -sS -d "name=Ada&lang=en" https://httpbin.org/post
{
  "args": {},
  "headers": {
    "Accept": "*/*",
    "Content-Length": "16",
    "Content-Type": "application/x-www-form-urlencoded",
    "Host": "httpbin.org",
    "User-Agent": "curl/8.22.0"
  },
  "method": "POST",
  "origin": "x.x.x.x",
  "url": "https://httpbin.org/post",
  "data": "",
  "files": {},
  "form": {
    "lang": "en",
    "name": "Ada"
  },
  "json": null
}
```

Several `-d` options are joined with `&`. `-d` sends the text as you typed it, so a value with `&` or a space breaks the form; `--data-urlencode` encodes it for you. With `-v` you can see the request line curl built: `> POST /post HTTP/1.1`, then `Content-Length: 3` and the form Content-Type for `-d "a=1"`.

## POST JSON: --json, or -H plus -d

On curl versions that have it (ours, 8.22.0, does), `--json` does three things at once: it sends the body, sets `Content-Type: application/json` and sets `Accept: application/json`. On an older curl, set the header yourself:

```bash
curl --json '{"name":"Ada"}' https://httpbin.org/post
curl -H "Content-Type: application/json" -d '{"name":"Ada","tags":["a","b"]}' https://httpbin.org/post
```

Both arrived as JSON: httpbin put the parsed object under `"json"`. The difference is the Accept header: `*/*` with `-H` and `-d`, `application/json` with `--json`. Without the Content-Type header, a body sent with plain `-d` is labelled as form data, and many JSON APIs reject it.

### The JSON body from a file

Put `@` before a file name to send the file's content. It is the cleanest way to send long JSON, and it worked unchanged in bash and in PowerShell:

```bash
$ cat body.json
{"query":"residential proxies","limit":5}
$ curl -sS --json @body.json https://httpbin.org/post
...
  "data": "{\"query\":\"residential proxies\",\"limit\":5}",
  "json": {
    "limit": 5,
    "query": "residential proxies"
  }
```

## POST JSON from Windows PowerShell and cmd

This is where most Windows users lose time. In Windows PowerShell 5.1, the command that works in bash sends broken JSON to curl.exe, because the inner double quotes are dropped on the way to the program:

| Shell and command | Body the server received |
| --- | --- |
| PowerShell 5.1: `curl.exe --json '{"name":"Ada"}' URL` | `{name:Ada}` (not valid JSON) |
| PowerShell 5.1: `curl.exe --json '{\"name\":\"Ada\"}' URL` | `{"name":"Ada"}` |
| PowerShell 5.1: `curl.exe --json '@body.json' URL` | the file, intact |
| cmd: `curl --json "{\"name\":\"Ada\"}" URL` | `{"name":"Ada"}` |

Two more Windows details: in PowerShell type `curl.exe`, because `curl` alone is an alias of Invoke-WebRequest; and quote `'@body.json'`, because `@` means something to PowerShell. The guide to [proxies in PowerShell](https://quanticdata.io/blog/powershell-proxy-setup/) covers the alias.

**Try it on your own targets.** Every QuanticData account gets $2 of free API usage per month.

[Start free — $2/month included](https://quanticdata.io/signup/?utm_source=blog&utm_medium=website&utm_campaign=blog-inline&utm_content=curl-post-request) · [Explore Residential Proxies from $0.80/GB](https://quanticdata.io/residential-proxies/)

## Upload a file with -F

```bash
$ printf 'id,name\n1,Ada\n' > rows.csv
$ curl -sS -F "file=@rows.csv" -F "note=test" https://httpbin.org/post
...
    "Content-Type": "multipart/form-data; boundary=------------------------6EbHxT81aN8yBlUZv89mhw",
...
  "files": {
    "file": "id,name\n1,Ada\n"
  },
  "form": {
    "note": "test"
  }
```

`-F "file=@rows.csv"` attaches the file as a part named `file`; `-F "note=test"` adds a plain field next to it. Use `-F` when a web form has a file input, and `-d` or `--json` for everything else.

## Status code, errors and redirects

- **Only the status:** `curl -sS -o /dev/null -w "%{http_code}\n" --json '{"a":1}' URL` printed `200`.
- **Fail on HTTP errors:** curl exits 0 on a 404 or 500 unless you add `-f`. With `-f` a POST to a 404 printed "curl: (22) The requested URL returned error: 404" and exited 22.
- **Redirects change the method.** With `-L`, a POST answered with 302 was followed as a GET and the form was lost; after a 307 curl kept the POST and the body. With `--post302` added, curl kept the POST after the 302 as well.
- **`-G` turns `-d` into a query string:** `curl -G -d "q=proxy" -d "page=2" URL` sent a GET to `/get?q=proxy&page=2`.
- **`-X POST` alone** sends a POST with no body; only use it when an API wants an empty POST.

## POST through a proxy

Add `-x` for the proxy and `-U` for its username and password; the POST options stay the same. httpbin's `origin` field shows the address the site saw:

```bash
curl -x http://residentialboson.quanticdata.io:10000 -U "USER-type-residential-country-us-session-ca01-lifetime-30:PASS" --json '{"via":"residential-basic"}' https://httpbin.org/post
curl -x http://mobile.quanticdata.io:8080 -U "USER-country-us-type-mobile-sid-ca03-ttl-30m:PASS" --json '{"via":"mobile"}' https://httpbin.org/post
curl -x http://residentialpremium.quanticdata.io:8080 -U "USER-country-de-sid-ca02-ttl-30m:PASS" -d "via=residential-premium" https://httpbin.org/post
```

| Network | Body | origin seen by the site | Echoed back |
| --- | --- | --- | --- |
| Residential Basic, US | JSON, 27 bytes | x.x.x.x (a US address) | `"json": {"via": "residential-basic"}` |
| Mobile, US | JSON, 16 bytes | x.x.x.x (a US address) | `"json": {"via": "mobile"}` |
| Residential Premium, Germany | form, 23 bytes | x.x.x.x (a German address) | `"form": {"via": "residential-premium"}` |

Headers and body went through unchanged; only the origin changed. Use one session ID for the steps of one form. Gateways, sticky sessions and SOCKS5 are in [how to use a proxy with curl](https://quanticdata.io/blog/how-to-use-a-proxy-with-curl/); a wrong proxy password shows as [407 Proxy Authentication Required](https://quanticdata.io/blog/how-to-fix-407-proxy-authentication-required/).

## Which network for POST jobs

| Plan | Tested here with | Good for |
| --- | --- | --- |
| Residential Basic | --json through residentialboson.quanticdata.io:10000 | Search and form endpoints that answer differently by country |
| Residential Premium | -d through residentialpremium.quanticdata.io:8080 | Home IPs in the country you pick, with a session time you set |
| Mobile | --json through mobile.quanticdata.io:8080 | Requests that should come from a mobile carrier IP |

Plans are on the pages for [residential proxies](https://quanticdata.io/residential-proxies/) and [mobile proxies](https://quanticdata.io/mobile-proxies/), and there is a [Residential Basic free trial](https://quanticdata.io/residential-proxy-free-trial/). When you would rather get a page back as clean data from one API call, see our [web scraping API](https://quanticdata.io/web-scraping-api/).

### Sources & further reading

- [curl manual: -d, --data](https://curl.se/docs/manpage.html#-d)
- [curl manual: --json](https://curl.se/docs/manpage.html#--json)
- [curl manual: -F, --form](https://curl.se/docs/manpage.html#-F)
- [httpbin.org request echo service](https://httpbin.org/)

## FAQ

Quick answers on curl post request.

[Something else? Ask us](mailto:hello@quanticdata.io)

### How do I send a POST request with curl?

Give curl a body: `curl -d "name=Ada" URL` for form data, `curl --json '{"name":"Ada"}' URL` for JSON, `curl -F "file=@rows.csv" URL` for a file. Each one makes the request a POST, so `-X POST` is not needed.

### How do I POST JSON with curl?

Use `--json '{"key":"value"}'`, which also sets Content-Type and Accept to application/json. On an older curl, use `-H "Content-Type: application/json" -d '{"key":"value"}'`. For long JSON, keep it in a file and send `--json @body.json`.

### Why does my JSON arrive broken when I use curl in PowerShell?

Windows PowerShell 5.1 drops the inner double quotes when it passes the argument to curl.exe: in our test `'{"name":"Ada"}'` arrived as `{name:Ada}`. Escape the quotes as `\"`, or put the JSON in a file and send `--json '@body.json'`.

### Do I need -X POST with curl -d?

No. `-d`, `--json` and `-F` already make the request a POST. `-X POST` on its own sends a POST without a body.

### How do I upload a file with a curl POST?

Use `-F "file=@path/to/file"`. curl sends multipart/form-data with the file as a part named `file`; add more `-F name=value` options for the other fields of the form.

### How do I send a curl POST through a proxy?

Add `-x http://HOST:PORT -U "USER:PASS"` to the same command. We posted JSON through Residential Basic and Mobile and form data through Residential Premium: the body arrived unchanged and the site saw the proxy IP.

## POST from a home or carrier IP

Residential and mobile proxies with country targeting and sticky sessions, ready for curl -x on every request.

[Start free — $2/month included](https://quanticdata.io/signup/?utm_source=blog&utm_medium=website&utm_campaign=blog-end&utm_content=curl-post-request) · [Explore Residential Proxies from $0.80/GB](https://quanticdata.io/residential-proxies/)

## Related reading

- [curl Basic Auth: -u, Header, .netrc, Proxy](https://quanticdata.io/blog/curl-basic-auth/): Proxies · curl -u user:password sends HTTP basic authentication: curl base64-encodes the pair into an Authorization header. Below: the header we captured with -v, the same header built by hand, passwords with colons and @, the prompt, .netrc, digest, and why a proxy login goes in -U, not -u.
- [curl Download File: -O, -o, -L and Resume](https://quanticdata.io/blog/curl-download-file/): Proxies · curl -O URL saves the file under its remote name, curl -o name URL under the name you choose, and -L follows redirects such as GitHub's. Below: every option run for real, including the 0-byte file a 302 leaves behind, a resumed download that matched the original byte for byte, and 1 MB through residential and mobile proxies.
- [curl Show Response Headers and Send Headers](https://quanticdata.io/blog/curl-headers/): Proxies · curl -i prints the response headers with the body, -I only the headers (with a HEAD request), and -D - -o /dev/null the headers of a normal GET. To send headers, use -H "Name: value", once per header. Below: all of it run for real, plus a single header with -w, removing curl's defaults, headers from a file, and what a proxy sees.

---

Source: https://quanticdata.io/blog/curl-post-request/ · Site index for AI: https://quanticdata.io/llms.txt
