# Send form-urlencoded with cURL in Rust

Paste a curl command that sends form-urlencoded and get idiomatic Rust code. We pick the right serialization for reqwest and set the correct Content-Type.

## Example

```bash
curl -X POST https://api.example.com/login \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "username=ada&password=lovelace"
```

## What the converter handles

- Content-Type is detected from -H headers first, then inferred from the body shape when the header is missing.
- application/x-www-form-urlencoded bodies are decoded into structured pairs so reqwest owns the encoding — you never double-encode a value.
- Charset directives on Content-Type (e.g. application/json; charset=utf-8) survive the round trip.

## Common mistakes

- Setting Content-Type manually and then also using reqwest's helper — you end up with duplicate headers or the wrong one wins.
- Mixing form encoding with JSON headers — the server rejects with 400 and it's easy to miss in code review.
- Trusting the browser DevTools "Copy as cURL" to preserve charset — it often drops it. Clean panel restores common defaults.

## FAQ

### How is form-urlencoded encoded in the generated Rust?

application/x-www-form-urlencoded bodies map to the right primitive in each language — data= in Python, url.Values in Go, FormUrlEncodedContent in C#.

### Does it preserve Content-Type?

Yes. The Content-Type header is honored and matched against the body so serialization stays consistent.

### Is anything uploaded?

No. Parsing and generation happen entirely in your browser.

---

Source: https://toolpaper.manavdev.site/how-to/send-form-with-curl-in-rust · Language hub: https://toolpaper.manavdev.site/curl-to-rust