# Send XML with cURL in C#

Paste a curl command that sends XML and get idiomatic C# code. We pick the right serialization for HttpClient and set the correct Content-Type.

## Example

```bash
curl -X POST https://api.example.com/users \
  -H "Content-Type: application/xml" \
  -d '<user><name>Ada</name></user>'
```

## What the converter handles

- Content-Type is detected from -H headers first, then inferred from the body shape when the header is missing.
- The XML body is preserved byte-for-byte; only Content-Type and Content-Length are managed for you.
- 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 HttpClient'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 XML encoded in the generated C#?

The XML body is passed through as a string with Content-Type: application/xml preserved.

### 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-xml-with-curl-in-csharp · Language hub: https://toolpaper.manavdev.site/curl-to-csharp