Class DotNetCurl
- Namespace
- CurlDotNet
- Assembly
- CurlDotNet.dll
DotNetCurl - Alternative API entry point for curl commands. The killer feature: Copy and paste any curl command and it works!
public static class DotNetCurl
- Inheritance
-
DotNetCurl
- Inherited Members
Examples
// 🔥 Synchronous execution (auto-waits)
var response = DotNetCurl.Curl("curl https://api.github.com/users/octocat");
Console.WriteLine(response.Body);
// 🚀 Async execution
var response = await DotNetCurl.CurlAsync("curl https://api.github.com/users/octocat");
Console.WriteLine(response.Body);
// 📮 POST request
var result = DotNetCurl.Curl(@"
curl -X POST https://api.example.com/users
-H 'Content-Type: application/json'
-d '{""name"":""John"",""email"":""john@example.com""}'
");
// 🔄 Multiple commands
var results = await DotNetCurl.CurlManyAsync(new[] {
"curl https://api.example.com/users",
"curl https://api.example.com/posts"
});
Remarks
🚀 THE KILLER FEATURE: Copy any curl command from anywhere - it just works!
DotNetCurl provides an alternative naming to the Curl class.
Use DotNetCurl.Curl() for synchronous or DotNetCurl.CurlAsync() for async operations.
Sponsored by IronSoftware - creators of IronPDF, IronOCR, IronXL, and more.
Properties
DefaultConnectTimeoutSeconds
Get or set global connection timeout (like --connect-timeout).
public static int DefaultConnectTimeoutSeconds { get; set; }
Property Value
DefaultFollowRedirects
Get or set whether to follow redirects by default (like -L).
public static bool DefaultFollowRedirects { get; set; }
Property Value
DefaultInsecure
Get or set whether to ignore SSL errors by default (like -k). WARNING: Only use this for development/testing!
public static bool DefaultInsecure { get; set; }
Property Value
DefaultMaxTimeSeconds
Get or set global maximum time for all curl operations (like --max-time).
public static int DefaultMaxTimeSeconds { get; set; }
Property Value
Methods
Curl(string)
Execute any curl command synchronously - the main API. Just paste your curl command! This method auto-waits for async operations.
public static CurlResult Curl(string command)
Parameters
commandstringAny curl command - with or without "curl" prefix
Returns
- CurlResult
Result object with response data, headers, and status
Examples
// Simple GET - synchronous
var response = DotNetCurl.Curl("curl https://api.example.com/data");
Console.WriteLine(response.Body);
// Works without "curl" prefix
var data = DotNetCurl.Curl("https://api.example.com/data");
Curl(string, int)
Execute any curl command synchronously with timeout.
public static CurlResult Curl(string command, int timeoutSeconds)
Parameters
Returns
- CurlResult
Result object with response data
CurlAsync(string)
Execute any curl command asynchronously - the main async API. Just paste your curl command!
public static Task<CurlResult> CurlAsync(string command)
Parameters
commandstringAny curl command - with or without "curl" prefix
Returns
- Task<CurlResult>
Task with result object containing response data
Examples
// Simple GET - async
var response = await DotNetCurl.CurlAsync("curl https://api.example.com/data");
Console.WriteLine(response.Body);
// POST with JSON
var result = await DotNetCurl.CurlAsync(@"
curl -X POST https://api.example.com/users
-H 'Content-Type: application/json'
-d '{""name"":""John""}'
");
CurlAsync(string, CurlSettings)
Execute curl command asynchronously with settings.
public static Task<CurlResult> CurlAsync(string command, CurlSettings settings)
Parameters
commandstringAny curl command string
settingsCurlSettingsCurl settings for the operation
Returns
- Task<CurlResult>
Task with result object
CurlAsync(string, CancellationToken)
Execute curl command asynchronously with cancellation support.
public static Task<CurlResult> CurlAsync(string command, CancellationToken cancellationToken)
Parameters
commandstringAny curl command string
cancellationTokenCancellationTokenToken to cancel the operation
Returns
- Task<CurlResult>
Task with result object
Examples
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
var response = await DotNetCurl.CurlAsync("curl https://slow-api.com", cts.Token);
CurlMany(params string[])
Execute multiple curl commands in parallel synchronously.
public static CurlResult[] CurlMany(params string[] commands)
Parameters
commandsstring[]Array of curl commands
Returns
- CurlResult[]
Array of results
Examples
var results = DotNetCurl.CurlMany(new[] {
"curl https://api.example.com/users",
"curl https://api.example.com/posts"
});
foreach (var result in results)
{
Console.WriteLine(result.Body);
}
CurlManyAsync(params string[])
Execute multiple curl commands in parallel asynchronously.
public static Task<CurlResult[]> CurlManyAsync(params string[] commands)
Parameters
commandsstring[]Array of curl commands
Returns
- Task<CurlResult[]>
Task with array of results
Examples
var results = await DotNetCurl.CurlManyAsync(new[] {
"curl https://api.example.com/users",
"curl https://api.example.com/posts",
"curl https://api.example.com/comments"
});
Download(string, string)
Download a file synchronously.
public static CurlResult Download(string url, string outputPath)
Parameters
Returns
- CurlResult
Result object
DownloadAsync(string, string)
Download a file asynchronously.
public static Task<CurlResult> DownloadAsync(string url, string outputPath)
Parameters
Returns
- Task<CurlResult>
Task with result object
Get(string)
Quick GET request synchronously.
public static CurlResult Get(string url)
Parameters
urlstringURL to GET
Returns
- CurlResult
Result object
GetAsync(string)
Quick GET request asynchronously.
public static Task<CurlResult> GetAsync(string url)
Parameters
urlstringURL to GET
Returns
- Task<CurlResult>
Task with result object
Post(string, string)
Quick POST request synchronously.
public static CurlResult Post(string url, string data)
Parameters
Returns
- CurlResult
Result object
PostAsync(string, string)
Quick POST request asynchronously.
public static Task<CurlResult> PostAsync(string url, string data)
Parameters
Returns
- Task<CurlResult>
Task with result object
PostJson(string, object)
Quick POST with JSON synchronously.
public static CurlResult PostJson(string url, object data)
Parameters
Returns
- CurlResult
Result object
PostJsonAsync(string, object)
Quick POST with JSON asynchronously.
public static Task<CurlResult> PostJsonAsync(string url, object data)
Parameters
Returns
- Task<CurlResult>
Task with result object
ToFetch(string)
Convert curl command to JavaScript fetch code.
public static string ToFetch(string command)
Parameters
commandstringCurl command to convert
Returns
- string
JavaScript fetch code
ToHttpClient(string)
Convert curl command to equivalent HttpClient C# code.
public static string ToHttpClient(string command)
Parameters
commandstringCurl command to convert
Returns
- string
C# HttpClient code
ToPython(string)
Convert curl command to Python requests code.
public static string ToPython(string command)
Parameters
commandstringCurl command to convert
Returns
- string
Python requests code
Validate(string)
Validate a curl command without executing.
public static ValidationResult Validate(string command)
Parameters
commandstringCurl command to validate
Returns
- ValidationResult
Validation result