简体   繁体   中英

How to send oauth_token and client_id in the request body of GraphQL Client endpoint in c#

Hello friends I want pass oauth_token and client_id in request body of a GraphQL Client. So how can I pass them, because GraphQLRequest has only three fields (ie Query , Variables and OperationName). Please suggest.

using GraphQL.Client;

var heroRequest = new GraphQLRequest{ Query = Query };
var graphQLClient = new GraphQLClient("URL");

var  graphQLResponse = await graphQLClient.PostAsync(heroRequest);

You can add the Authorization (or any other parameter) to the Header using the DefaultRequestHeaders from GraphQLClient .

var graphClient = new GraphQLClient("https://api.github.com/graphql");
graphClient.DefaultRequestHeaders.Add("Authorization", $"bearer {ApiKey}");

var request = new GraphQLRequest
{
    Query = @"query { viewer { login } }"
};

var test = await graphClient.PostAsync(request);

Here you can find more detailed information about the DefaultRequestHeaders from HttpClient: Setting Authorization Header of HttpClient

Also, there's a related issue created on graphql-dotnet git.
https://github.com/graphql-dotnet/graphql-client/issues/32

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM