This ASP.NET Core app converts curl commands to C# code
https://t.me/curl_to_csharp_bot
- Run container
docker run -p 8080:80 olsh/curl-to-csharp
You can grab latest binaries here and run dotnet CurlToCSharp.dll
- Install cake
dotnet tool install -g Cake.Tool
- Run build
dotnet cake build.cake
- Parses cURL command into individual cURL options.
- Returns parsing errors and warnings if the cURL input is invalid.
Install with NuGet
dotnet add package Curl.CommandLine.Parser
var input = @"curl https://sentry.io/api/0/projects/1/groups/?status=unresolved -d '{""status"": ""resolved""}' -H 'Content-Type: application/json' -u 'username:password' -H 'Accept: application/json' -H 'User-Agent: curl/7.60.0'";
var output = new CurlParser(new ParsingOptions() { MaxUploadFiles = 10 }).Parse(input);
Console.WriteLine(output.Data.UploadData.First().Content);
// Output:
// {"status": "resolved"}
- Converts output from CurlParser into C# code.
- Returns parsing errors and warnings if the cURL input is invalid.
Install with NuGet
dotnet add package Curl.HttpClient.Converter
var input = @"curl https://sentry.io/api/0/projects/1/groups/?status=unresolved -d '{""status"": ""resolved""}' -H 'Content-Type: application/json' -u 'username:password' -H 'Accept: application/json' -H 'User-Agent: curl/7.60.0'";
var curlOption = new CurlParser().Parse(input);
var output = new CurlHttpClientConverter().ToCsharp(curlOption.Data);
// Output:
/*
// In production code, don't destroy the HttpClient through using, but better reuse an existing instance
// https://www.aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/
using (var httpClient = new HttpClient())
{
using (var request = new HttpRequestMessage(new HttpMethod("POST"), "https://sentry.io/api/0/projects/1/groups/?status=unresolved"))
{
request.Headers.TryAddWithoutValidation("Accept", "application/json");
request.Headers.TryAddWithoutValidation("User-Agent", "curl/7.60.0");
var base64authorization = Convert.ToBase64String(Encoding.ASCII.GetBytes("username:password"));
request.Headers.TryAddWithoutValidation("Authorization", $"Basic {base64authorization}");
request.Content = new StringContent("{\"status\": \"resolved\"}");
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
var response = await httpClient.SendAsync(request);
}
}
*/