graphql-dotnet / graphql-dotnet/graphql-client
Adding Custom Header to GraphQLHttpClient
- Dominant language
- C#
- Stars
- 648
- Forks
- 136
- PR merge metrics
- No merged PRs in 30d
Description
Hi there:
I have got a GraphQL Client instance which is tying to call a GraphQL API endpoint. My code looks like below:
`var graphQLClient = new GraphQLHttpClient("https://abc.com/graphql", new NewtonsoftJsonSerializer());
var raceRequest = new GraphQLRequest {
Query = @"
query ($input: GetRaceResultsInput, $before: String, $after: String, $first: Int, $last: Int) {
getRaceResults(before: $before, after: $after, first: $first, last: $last, input: $input) {
edges {
cursor
node {
raceId
horses {
horseId
}
}
}
}
}"
};
var graphQLResponse = await graphQLClient.SendQueryAsync(raceRequest);`
RaceResult is of the format:
**public class RaceResult
{
public string Result { get; set; }
}**
When the SendQueryAsync is excuted, I get the following error:
**System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
System.ComponentModel.Win32Exception (0x80090326): The message received was unexpected or badly formatted.**
My request header in postman has got custom key value pair like **x-developer-secret** and I get the desired result. Is there anyway to add customer header before calling the API? I tried the following:
**graphQLClient.HttpClient.DefaultRequestHeaders.Add("Authorization", $"bearer abcsecret");**
However it didn't work. Any help would be appreciated.
Thanks
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.