Skip to the content.

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

  1. curl GET request in C# - run a curl command, check the status code, read headers and the body
  2. curl -X POST JSON in C# - -d with a Content-Type header, --json, the WithJson builder, ParseJson<T>()
  3. curl -d form data POST in C# - URL-encoded forms, --data-urlencode, WithFormData
  4. curl -F file upload in C# - multipart/form-data, extra fields, -T/--upload-file PUT uploads, --data-binary
  5. curl download file in C# (curl -o) - -o, -O, -J, --output-dir, resuming with -C -, Curl.DownloadAsync, SaveToFile
  6. Handle curl errors and exceptions in C# - HTTP status results, -f, EnsureSuccess(), timeouts, connection failures, cancellation, --retry
  7. Call a REST API with curl in C# - bearer tokens, all the verbs, a reusable LibCurl client

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.