Skip to main content
Back to tools

cURL to C#

Convert a curl command to C# HttpClient

About cURL to C#

Creates async C# code that sends an HttpRequestMessage through HttpClient from System.Net.Http and prints the body with Console.WriteLine. The Content-Type header moves into StringContent, -F fields become FormUrlEncodedContent, and non-standard verbs use new HttpMethod. The result is top-level statements for a .NET console app, generated in your browser without a server round trip.

Category: API.

Frequently asked questions

Is the generated C# code synchronous or async?

▾

Async. It sends an HttpRequestMessage with await client.SendAsync(request) and reads the body with await response.Content.ReadAsStringAsync(). The code is written as top-level statements for a .NET 6+ console app, whose default implicit usings supply Console and Dictionary; inside a class, put it in an async Task method.

Why is Content-Type not added with request.Headers.Add?

▾

In .NET, Content-Type belongs to the request content, so when there is a body its value becomes the media type of new StringContent(body, Encoding.UTF8, ...), or text/plain when the command sets none. Keep that argument a bare type such as application/json, because StringContent rejects parameters like charset there.

What do -F and -u turn into in the C# code?

▾

-F fields become FormUrlEncodedContent built from a Dictionary<string, string>, so they are sent URL-encoded rather than as MultipartFormDataContent. -u user:pass becomes request.Headers.Add with an Authorization: Basic value whose Base64 is precomputed.

Are -k and -L translated, and should I reuse HttpClient?

▾

Neither is translated: HttpClient follows redirects by default, and skipping certificate checks would need an HttpClientHandler with ServerCertificateCustomValidationCallback. The snippet creates one HttpClient for a single call; in long-running apps, reuse one instance or use IHttpClientFactory.

Related tools