【发布时间】:2018-07-19 15:44:39
【问题描述】:
我正在尝试通过 powershell 与Graphql api 进行通信。根据 Github,必须首先执行以下 curl 调用。
curl -H "Authorization: bearer token" -X POST -d " \
{ \
\"query\": \"query { viewer { login }}\" \
} \
" https://api.github.com/graphql
使用 GitHub Enterprise,我在 powershell 上执行以下调用:
$url = "http://github.company.com/api/graphql" # note that it's http, not https
$body = "`"query`":`"query { viewer { login }}`"" #`
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("content-type","application/json")
$headers.Add("Authorization","bearer myTokenNumber")
$response = Invoke-WebRequest -Uri $url -Method POST -Body $body -Headers $headers
我不断收到相同的错误消息,即解析 JSON 时出现问题。
我认为错误与body 标记有关,但我不知道如何。
echo $body 给"query":"query { viewer { login }}"
这里有什么问题?
确切的错误信息:
Invoke-WebRequest : {"message":"Problems parsing JSON","documentation_url":"https://developer.github.com/v3"}
At line:1 char:13
+ $response = Invoke-WebRequest -Uri $url -Method POST -Body $body -Headers $heade ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
【问题讨论】:
-
你能分享一下确切的错误信息吗?
-
请立即查看
-
你在 GitHub 的 GraphQL Explorer Interface 中测试过你的令牌和查询吗?
-
在那里完美运行
-
你有理由必须使用
http版本吗?
标签: json powershell curl github graphql