cURL to C# Converter
Convert curl commands to C# code using HttpClient. Paste a command and the C# snippet appears instantly — everything runs in your browser.
- Instant ConversionCode updates as you type
- Multiple Languages40 languages, 61 libraries
- 100% Client SideYour data stays private
How to use this tool
Steps for using the cURL to Code.
- Copy a curl command — from API documentation, or from your browser's DevTools (Network tab → right-click a request → Copy as cURL (bash)).
- Paste it into Enter cURL command. The C# HttpClient code appears instantly.
- Set up: HttpClient is part of .NET — no package is needed. The code uses top-level statements (.NET 6 or later).
- Run it: Create a console app with
dotnet new console, replaceProgram.cswith the code and rundotnet run. Replace placeholders such asYOUR_TOKENfirst, and check any notes under the editors for curl options that have no HttpClient equivalent.
Example
GET with headers → C# HttpClient
curl 'https://api.example.com/v1/users?page=2' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer YOUR_TOKEN'using System;
using System.Net.Http;
using var client = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Get, "https://api.example.com/v1/users?page=2");
request.Headers.TryAddWithoutValidation("Accept", "application/json");
request.Headers.TryAddWithoutValidation("Authorization", "Bearer YOUR_TOKEN");
using var response = await client.SendAsync(request);
Console.WriteLine((int)response.StatusCode);
Console.WriteLine(await response.Content.ReadAsStringAsync());Common use cases
- ASP.NET and worker services calling APIs
- Desktop and console tools
- Integration tests
Converting curl to C# HttpClient
HttpClient (System.Net.Http) is .NET's built-in HTTP client. The code uses HttpRequestMessage so any method, headers and body from the curl command carry over.
The converter reads the curl command the way curl does — the method (-X), headers (-H), request bodies (-d, --data-raw, --json, -F), query strings, basic auth (-u) and cookies — and writes the equivalent HttpClient code. Options that have no HttpClient equivalent are listed under the editors rather than silently dropped.
Limitations
- In real applications, reuse one HttpClient (or IHttpClientFactory) instead of creating one per request.
- The code is a starting point: add timeouts, retries and error handling for production use.
- Secrets in the curl command are copied into the code — move them to environment variables before committing.
Frequently asked questions
Should I create a new HttpClient for every request?
No. Reuse a single instance or use IHttpClientFactory; creating many clients can exhaust sockets. The generated code creates one for a single request.
Why TryAddWithoutValidation for headers?
It copies header values exactly as curl sent them, without .NET rejecting unusual formats such as some Authorization values.
Is my curl command sent to a server?
No. The conversion runs entirely in your browser, so tokens and passwords in the command never leave your device. Still, replace real secrets before sharing the generated code.