cURL converter · C#
cURL to C#
Paste a curl command and get a clean HttpClient snippet. We split content-headers from request-headers so ContentType lands on StringContent, wire --max-time into HttpClient.Timeout, and map --compressed to AutomaticDecompression.All.
InputcURL command
1 secret
MethodPOST·Headers2·Body46 B· Chars 187
Output.NET · HttpClient(.NET)
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
class Program {
static async Task Main() {
using var handler = new HttpClientHandler { AllowAutoRedirect = false };
using var client = new HttpClient(handler);
using var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api.example.com/v1/messages");
request.Headers.TryAddWithoutValidation("Authorization", "Bearer sk_test_123");
request.Content = new StringContent("{\"to\":\"+15551234567\",\"body\":\"Hello from curl\"}", Encoding.UTF8, "application/json");
using var response = await client.SendAsync(request);
var text = await response.Content.ReadAsStringAsync();
Console.WriteLine(text);
}
}Inspect
Top guides for C#
All guides →Common questions
- Why not WebRequest / HttpWebRequest?
- HttpClient is the modern .NET path — connection reuse, async by default, and the only client actively maintained. HttpWebRequest is legacy and Microsoft steers you away from it.
- How are headers split?
- Content-Type and Content-Length belong on HttpContent, not the HttpRequestMessage. We route them correctly so .NET doesn't throw at runtime.
- Does --compressed work?
- Yes. We set HttpClientHandler.AutomaticDecompression = DecompressionMethods.All so gzip/deflate/brotli responses are transparently decoded.
- Is my curl sent anywhere?
- No. Parsing and code generation happen entirely in your browser.
Also convert cURL to
All guides →Same parser, same idiomatic output — swap the target language whenever your stack changes. Every hub carries its own reference guides for methods, payloads, and auth.