cURL to C#

Paste a curl command and get C# HttpClient code, with headers and content split the way .NET expects.

cURL to C# runs entirely in your browser. Commands you paste — including any tokens in them — are converted on your device and never uploaded.

Open cURL to Java

About cURL to C#

Copying a curl command out of API documentation and rewriting it as C# is a small task that goes wrong in one predictable place: .NET splits headers between the request and its content. Content-Type belongs to HttpContent, not to HttpRequestMessage, and setting it on the wrong one throws an InvalidOperationException at runtime rather than failing to compile. This converter parses the curl flags — method, headers, body, and the -u flag that becomes Basic auth — and emits an HttpClient program with the headers on the correct object, the body wrapped in a StringContent with the right media type, and the response printed.

Features

How to use the cURL to C#

  1. Paste the curl command, including its headers and body
  2. Read the generated C# — the code appears as you type
  3. Copy it, or download Program.cs
  4. Check any warnings about flags that were not translated

Example

Input

curl -X POST https://api.example.com/users -H "Content-Type: application/json" -d '{"name":"Ada"}'

Output

request.Content = new StringContent(
    "{\"name\":\"Ada\"}",
    Encoding.UTF8,
    "application/json");

The media type goes to StringContent, not to request.Headers — the mistake that produces a runtime exception.

Common errors & troubleshooting

Frequently asked questions

How do I convert a curl command to C#?
Paste it above. The method, URL, headers and body are parsed and emitted as an HttpClient program, with content headers placed on the content object where .NET requires them.
Why can't I set Content-Type on HttpRequestMessage?
Because .NET separates request headers from content headers, and Content-Type is a content header. Assigning it to request.Headers throws at runtime — it belongs on HttpContent.
How do I send Basic authentication in C#?
Base64-encode user:password and set it as an AuthenticationHeaderValue with the Basic scheme on the client's DefaultRequestHeaders. The generated code does exactly that when the curl command uses -u.
Which .NET versions does the generated code target?
Anything with HttpClient and top-level async Main, so .NET Core 3.1 and later including .NET 5 through 9. The using var syntax needs C# 8 or newer.
Is my curl command sent anywhere?
No. It is parsed and converted in your browser, so tokens and API keys inside the command stay on your device.

Related tools

All ArrayKit tools