cURL to C#

Paste a curl command and get C# code using HttpClient — or pick any other language.

Paste a curl command above to generate code

How curl maps to C# (HttpClient)

  • →Uses HttpClient and HttpRequestMessage with top-level statements (.NET 6+).
  • →Content-Type moves onto the StringContent: .NET throws if you put it on the request headers.
  • →Reuse one HttpClient for your whole app (or IHttpClientFactory) — creating one per request exhausts sockets.

Frequently asked

Why can't I add Content-Type to HttpClient request headers?

In .NET, Content-Type is a content header. Set it through the HttpContent, e.g. new StringContent(body, Encoding.UTF8, "application/json"), which is what the converter does.

Is it OK to create a new HttpClient for every call?

No. Each instance holds its own connections, and creating many can exhaust sockets. Keep a single instance or use IHttpClientFactory.

ToolNinja