How to do common curl tasks in C#
Each guide below answers one curl-in-C# question with a curl command you can paste into Curl.ExecuteAsync, the equivalent fluent CurlRequestBuilder code, and the gotchas we found when running it against CurlDotNet 9.8.0.
dotnet add package CurlDotNet
Getting started
| Guide | Question it answers |
|---|---|
| Run a curl command in C# | How do I run a curl command in C#? |
| Convert curl to C# | How do I turn a curl command into HttpClient, Python, fetch or PowerShell code? |
| curl flavors: bash, CMD, PowerShell, Invoke-WebRequest | Why does the same pasted command send different bytes from bash, cmd.exe and PowerShell, and how do I pick the right CurlFlavor? |
| Run curl synchronously | How do I make a blocking call with Curl.Execute in a console app or script? |
| How CurlDotNet works | What happens between the curl string and the HTTP request? |
| curl vs HttpClient | When should I use CurlDotNet and when raw HttpClient? |
Requests and data
| Guide | Question it answers |
|---|---|
| POST JSON | How do I send curl -X POST JSON in C#? |
| PUT, DELETE and PATCH | How do I send the other REST verbs? |
| HEAD requests | How do I run curl -I to read headers only? |
| Custom headers and User-Agent | How do I set -H, -A, -e and -b? |
| Multipart upload with -F | How do I upload a file with curl -F? |
| Download a file with -o | How do I download a file, binary-safe? |
| Parse JSON responses | How do I turn the response into C# objects? |
Authentication and security
| Guide | Question it answers |
|---|---|
| Bearer token | How do I send Authorization: Bearer? |
| Basic auth with -u | How do I use curl -u, --digest or --ntlm? |
| Ignore SSL errors with -k | How do I use curl -k, and when is it safe? |
Network behavior
| Guide | Question it answers |
|---|---|
| Follow redirects with -L | How do I follow 3xx redirects? |
| Timeouts with -m | How do I set a timeout or cancel a request? |
| Proxy with -x | How do I go through an HTTP or SOCKS5 proxy? |
| Error handling | What is thrown, what is not, and how do I retry with --retry? |
Application types
| Guide | Question it answers |
|---|---|
| ASP.NET Core | How do I register CurlDotNet in DI and call it from controllers or minimal APIs? |
| Blazor and .NET MAUI | How do I use it in Blazor Server, WebAssembly and MAUI? |
| Azure Functions and AWS Lambda | How do I use it in serverless functions? |
PowerShell
Using CurlDotNet from PowerShell or .csx scripts? See Using CurlDotNet from PowerShell and .NET scripts.
About CurlDotNet
CurlDotNet is a pure C# library (no curl.exe, no native libcurl, no P/Invoke) for netstandard2.0, .NET Framework 4.7.2 and 4.8, and .NET 8, 9 and 10. It is MIT licensed, written by Jacob Mellor and sponsored by Iron Software. Source: github.com/jacob-mellor/curl-dot-net.