Beginner curl recipes in C#
These beginner curl recipes in C# cover the first things most people need from CurlDotNet: fetch a URL, send JSON or a form, move files up and down, handle errors and talk to a REST API. Work through them in order, or jump to the one that matches your task.
Contents
- curl GET request in C# - run a curl command, check the status code, read headers and the body
- curl -X POST JSON in C# -
-dwith aContent-Typeheader,--json, theWithJsonbuilder,ParseJson<T>() - curl -d form data POST in C# - URL-encoded forms,
--data-urlencode,WithFormData - curl -F file upload in C# - multipart/form-data, extra fields,
-T/--upload-filePUT uploads,--data-binary - curl download file in C# (curl -o) -
-o,-O,-J,--output-dir, resuming with-C -,Curl.DownloadAsync,SaveToFile - Handle curl errors and exceptions in C# - HTTP status results,
-f,EnsureSuccess(), timeouts, connection failures, cancellation,--retry - Call a REST API with curl in C# - bearer tokens, all the verbs, a reusable
LibCurlclient
Next
The one-flag-at-a-time recipes cover redirects, cookies, proxies, timeouts, retries, HEAD requests, PUT/DELETE/PATCH and authentication schemes. When a command fails with a curl exit code, the curl exit code reference lists the matching exception.