From 96a8e523ba7db97d3d9aa58a55f72a34128f316c Mon Sep 17 00:00:00 2001 From: Vivek Jayachandran Date: Sun, 10 Sep 2023 20:32:52 +1200 Subject: [PATCH] Explicitly setting content header to avoid issues with some GrahQL servers. For instance synthetic GraphQL generated out of Azure APIM. --- src/GraphQL.Client/GraphQLHttpRequest.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/GraphQL.Client/GraphQLHttpRequest.cs b/src/GraphQL.Client/GraphQLHttpRequest.cs index c9d4e01a..d03b9f8e 100644 --- a/src/GraphQL.Client/GraphQLHttpRequest.cs +++ b/src/GraphQL.Client/GraphQLHttpRequest.cs @@ -35,7 +35,10 @@ public virtual HttpRequestMessage ToHttpRequestMessage(GraphQLHttpClientOptions }; message.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/graphql-response+json")); message.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - message.Headers.AcceptCharset.Add(new StringWithQualityHeaderValue("utf-8")); + message.Headers.AcceptCharset.Add(new StringWithQualityHeaderValue("utf-8")); + + // Explicitly setting content header to avoid issues with some GrahQL servers + message.Content.Headers.ContentType = new MediaTypeHeaderValue(options.MediaType); if (options.DefaultUserAgentRequestHeader != null) message.Headers.UserAgent.Add(options.DefaultUserAgentRequestHeader);