cURL with Bearer token in C#
Paste a curl command that uses Bearer token and get C# code using HttpClient. Toolpaper also detects secrets and offers a one-click redaction before sharing.
Quick answer
To convert a cURL command to C#, paste it into the Toolpaper workbench below. It parses the command in your browser and emits idiomatic C# code — headers, query string, request body, authentication (Bearer, Basic, API key), and cookies are all wired up automatically. No data is uploaded; conversion is fully client-side.
Prefer a different target? See the full cURL to C# reference, or jump to the same guide in JavaScript, Node.js, or Python.
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
class Program {
static async Task Main() {
using var handler = new HttpClientHandler { AllowAutoRedirect = false };
using var client = new HttpClient(handler);
using var request = new HttpRequestMessage(new HttpMethod("GET"), "https://api.example.com/me");
request.Headers.TryAddWithoutValidation("Authorization", "Bearer YOUR_TOKEN");
using var response = await client.SendAsync(request);
var text = await response.Content.ReadAsStringAsync();
Console.WriteLine(text);
}
}Example
A representative curl command for this scenario. Paste your own above to convert an exact match.
curl https://api.example.com/me \
-H "Authorization: Bearer YOUR_TOKEN"Implementation notes
- Authorization: Bearer <token> is preserved verbatim so JWT signatures stay intact — no re-encoding, no whitespace normalization.
- Secrets are visible in the parsed request. Use the Clean panel's redact-and-diff flow before you paste the command anywhere.
- Shareable links Base64-encode the input — they never leave your browser, and cleaned versions produce different links.
Common mistakes
- Pasting a Bearer token straight into a public repo — the Clean panel flags common JWT and opaque-token shapes.
- Not rotating a leaked credential because "it's only in a screenshot" — screenshots get OCR'd, redact first.
- Trusting HTTPS alone for API keys in query strings — proxies log URLs. Prefer headers, which the converter defaults to.
Common questions
- How is Bearer token rendered in C#?
- The Authorization: Bearer header passes through to the generated request as-is. Use Toolpaper's Clean panel to redact the token before sharing.
- Can I redact the secret before sharing?
- Yes. Open the Clean panel — Toolpaper detects Bearer tokens, Basic credentials, and common API-key patterns and replaces them with <REDACTED> in a diffable view.
- Does anything leave my browser?
- No. Parsing, redaction, and generation are 100% client-side.
More auth flows in C#
C# hub →The same guide in other languages
All guides →In JavaScript
/how-to/curl-bearer-auth-in-javascript
In Node.js
/how-to/curl-bearer-auth-in-node
In Python
/how-to/curl-bearer-auth-in-python
In Go
/how-to/curl-bearer-auth-in-go
In PHP
/how-to/curl-bearer-auth-in-php
In Ruby
/how-to/curl-bearer-auth-in-ruby
In Rust
/how-to/curl-bearer-auth-in-rust
In Java
/how-to/curl-bearer-auth-in-java
Full C# reference on the cURL to C# hub, or open the main converter for all 18 targets.