Skip to the content.

CurlDotNet documentation — curl for C# and .NET

CurlDotNet is curl for C# and .NET: a pure-C# reimplementation of the curl command line that lets you run a curl command string directly in your .NET application and get a typed result back. No native libcurl binding, no Process.Start, no external curl binary.

using CurlDotNet;

var result = await Curl.ExecuteAsync("curl -H 'Accept: application/json' https://api.github.com/users/octocat");

Console.WriteLine(result.StatusCode);   // 200
Console.WriteLine(result.Body);         // JSON text

Like the curl tool, CurlDotNet sends User-Agent: curl/8.7.1 and Accept: */* unless you set your own, so APIs that insist on a User-Agent (GitHub’s, for example) work as they do from a terminal. Its behaviour is checked against curl’s own test suite: all 631 runnable curl tests pass (how CurlDotNet is tested).

Install CurlDotNet

dotnet add package CurlDotNet

CurlDotNet targets netstandard2.0, net472, net48, net8.0, net9.0 and net10.0. See the installation guide for IDE, Docker and .NET Framework notes.

Where to start

You are… Start here
New to curl New to curl? How to run curl commands in C#
New to .NET What is .NET?, then Your first request
An experienced .NET developer Quick start, then the API guide
Coming from HttpClient curl to HttpClient in C#
Coming from RestSharp RestSharp vs CurlDotNet

Three ways to use CurlDotNet

Run a curl command string

Paste the command from API docs, Stack Overflow or a shell script. The leading curl is optional.

using CurlDotNet;

var result = await Curl.ExecuteAsync(@"curl -X POST https://httpbin.org/post
    -H 'Content-Type: application/json'
    -d '{""name"":""Ada""}'");

if (result.IsSuccess)
    Console.WriteLine(result.Body);

Build the request fluently

CurlRequestBuilder gives you IntelliSense and compile-time checking. It produces the same request as the equivalent curl command.

using CurlDotNet.Core;

var result = await CurlRequestBuilder.Post("https://httpbin.org/post")
    .WithJson(new { name = "Ada" })
    .WithBearerToken("token123")
    .WithTimeout(TimeSpan.FromSeconds(30))
    .ExecuteAsync();

Reuse a configured client

LibCurl is an instance class you can register in dependency injection and share across requests.

using CurlDotNet.Lib;

using var curl = new LibCurl()
    .WithUserAgent("MyApp/1.0")
    .WithBearerToken("token123")
    .WithTimeout(TimeSpan.FromSeconds(30));

var result = await curl.GetAsync("https://api.github.com/user");

Common tasks

Documentation sections

Section What it covers
Getting started Installation, quick start, first request, configuration
Tutorials Step-by-step lessons for developers new to .NET or HTTP
Cookbook Copy-paste recipes for common tasks
API guide The three APIs, CurlResult, settings and exceptions
Guides Advanced usage, logging and observability
Migration Moving from HttpClient or RestSharp
Reference Which curl flags are supported, exit codes, libcurl mapping, how CurlDotNet is tested against curl’s test suite
Exceptions Every exception type and how to fix it
Troubleshooting Common issues and FAQ
API reference Generated from the XML documentation

Supported .NET versions

Details: Framework compatibility.

Getting help

CurlDotNet is sponsored by Iron Software.