【问题标题】:Can I send GraphQL queries with an httpclient in .NET core?我可以在 .NET 核心中使用 httpclient 发送 GraphQL 查询吗?
【发布时间】:2021-05-28 22:26:20
【问题描述】:
是否可以使用 .NET 核心中的标准 httpclient 发送 graphQL 查询?
当我尝试使用 client.post 发送查询时,我得到 "Expected { or [ as first syntax token."
如何使用 httpclient 发送 GraphQL 查询。
无需使用库(如 GraphQLHttpClient 等)
【问题讨论】:
标签:
asp.net-core
graphql
graphqlclient
【解决方案1】:
知道了:
只需将“查询”添加为 json 对象。像这样:
{"query" : "query { __schema { queryType { name } mutationType { name } types { name } directives { name } } }"}
在 .NET 中,您可以在 HTTP 帖子中使用它(不要忘记对双引号进行字符串转义
private static string myquery = "{ \"query\" : \"query { __schema { queryType { name } mutationType { name } types { name } directives { name } } }\" }";