cURL to C# Converter
Paste a cURL command and get equivalent C# built on HttpClient and HttpRequestMessage — the standard async HTTP API across modern .NET. The parser reads the method, repeated headers, request body, -u basic auth and cookies, then emits a new HttpRequestMessage(HttpMethod.X, url), sets request and content headers correctly, attaches a StringContent body, and awaits client.SendAsync(request). Everything runs in your browser.
How to use the cURL to C# Converter
Paste a cURL command into the cURL command field — a browser Copy as cURL string with backslash line continuations works. Press Convert to C# (it also converts as you type) and the C# code appears below. Click Example to load a JSON POST with a bearer token, then Copy the snippet. The output includes using System.Net.Http; (and System.Text; when there is a body) and uses top-level statements so it drops straight into a console project. It creates var client = new HttpClient(); and var request = new HttpRequestMessage(HttpMethod.Post, url);, adds each header with request.Headers.Add(name, value), and sets a JSON payload with request.Content = new StringContent(body, Encoding.UTF8, "application/json"). Content-type headers from the cURL command are applied to the content object, not the request. It awaits client.SendAsync(request), then prints (int)response.StatusCode and await response.Content.ReadAsStringAsync().
Converting cURL to C# with HttpClient
HttpClient is the canonical HTTP client across .NET Core, .NET 5+ and modern .NET Framework. The flexible pattern — the one this converter generates — pairs it with an explicit HttpRequestMessage, which lets you set any verb, any header, and any content in one place and send it with client.SendAsync(request). The convenience helpers like GetAsync and PostAsync are fine for simple calls, but a request message is what you reach for once custom headers or unusual methods are involved.
The part that surprises newcomers is the split between request headers and content headers. Content-Type and Content-Length belong to the body, so .NET enforces that they live on the HttpContent object, not on request.Headers; trying to add Content-Type via request.Headers.Add throws at runtime. This converter handles that for you: it routes content headers onto the StringContent — whose constructor takes the media type directly, e.g. new StringContent(body, Encoding.UTF8, "application/json") — and everything else onto request.Headers. It also drops Content-Length, which HttpContent computes automatically. Basic credentials from -u user:pass become a Base64 Authorization: Basic header.
The generated code is async, matching the API: every send and body read returns a Task, so the snippet uses top-level await. For the same request in another ecosystem, see the cURL to Python converter or the multi-language cURL converter.
Common use cases
- API integration — drop a third-party endpoint into a .NET service with headers and a JSON body wired correctly.
- DevTools to C# — turn a browser “Copy as cURL” into a working
HttpClientrequest. - Avoiding the header trap — get content headers placed on the content object so the code does not throw at runtime.
- Documentation — present an endpoint as idiomatic C# beside the shell example.
- Learning HttpClient — see the request-message pattern and the request-vs-content header split.
- Porting scripts — move a curl-based job into a compiled .NET program.
Frequently asked questions
Why are some headers added to the content instead of the request?
Content-Type to live on the HttpContent object. Adding them to request.Headers throws, so the converter routes them to the StringContent automatically.Does it use a third-party package like RestSharp?
System.Net.Http.HttpClient, so it works in any modern .NET project without extra NuGet packages.Why is the generated code async?
HttpClient is async-first — SendAsync and ReadAsStringAsync both return tasks. The snippet uses top-level await so it runs as-is in a console project.How is -u basic auth handled?
Authorization: Basic header on the request.