Send GraphQL with cURL in C#

Paste a curl command that sends GraphQL and get idiomatic C# code. We pick the right serialization for HttpClient and set the correct Content-Type.

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.

InputcURL command
MethodPOST·Headers1·Body34 B· Chars 128
Output.NET · HttpClient(.NET)
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("POST"), "https://api.example.com/graphql");
    request.Content = new StringContent("{\"query\":\"{ viewer { id name } }\"}", Encoding.UTF8, "application/json");
    using var response = await client.SendAsync(request);
    var text = await response.Content.ReadAsStringAsync();
    Console.WriteLine(text);
  }
}
Inspect

Example

A representative curl command for this scenario. Paste your own above to convert an exact match.

curl input
curl -X POST https://api.example.com/graphql \
  -H "Content-Type: application/json" \
  -d '{"query":"{ viewer { id name } }"}'

Implementation notes

  • Content-Type is detected from -H headers first, then inferred from the body shape when the header is missing.
  • GraphQL payloads keep their { query, variables, operationName } shape so persisted-query servers keep matching.
  • Charset directives on Content-Type (e.g. application/json; charset=utf-8) survive the round trip.

Common mistakes

  • Setting Content-Type manually and then also using HttpClient's helper — you end up with duplicate headers or the wrong one wins.
  • Mixing form encoding with JSON headers — the server rejects with 400 and it's easy to miss in code review.
  • Trusting the browser DevTools "Copy as cURL" to preserve charset — it often drops it. Clean panel restores common defaults.

Common questions

How is GraphQL encoded in the generated C#?
GraphQL queries are treated as JSON payloads with the { query, variables } shape intact.
Does it preserve Content-Type?
Yes. The Content-Type header is honored and matched against the body so serialization stays consistent.
Is anything uploaded?
No. Parsing and generation happen entirely in your browser.

More payload types in C#

C# hub →

The same guide in other languages

All guides →

Full C# reference on the cURL to C# hub, or open the main converter for all 18 targets.