powershell - 使用 PowerShell 查询 GraphQL
问题描述
所以我一直在尝试从 PowerShell 查询 GraphQL。一切在 cmd 中看起来都很完美,但我无法让它在 PS 中工作,看,到目前为止我有这个代码:
$oAuth2TokenUrl = "https://api.cloudflare.com/client/v4/zones/0000/analytics/dashboard"
$accessKey = '1111'
$Cloudflare_Oauth_Header = @{
"Authorization" = "Bearer $accessKey";
}
$query = @'
{ "query": "query { viewer {
zones(filter: {zoneTag: 0000}) {
httpRequests1mGroups(orderBy: [datetimeMinute_ASC], limit: 1000, filter: {datetime_geq: "2019-09-08T20:00:00Z", datetime_lt: "2019-09-08T20:02:00Z"}) {
dimensions {datetimeMinute}
sum {
browserMap {
pageViews
uaBrowserFamily
}
bytes
cachedBytes
cachedRequests
contentTypeMap {
bytes
requests
edgeResponseContentTypeName
}
clientSSLMap {
requests
clientSSLProtocol
}
countryMap {
bytes
requests
threats
clientCountryName
}
encryptedBytes
encryptedRequests
ipClassMap {
requests
ipType
}
pageViews
requests
responseStatusMap {
requests
edgeResponseStatus
}
threats
threatPathingMap {
requests
threatPathingName
}
}
uniq {
uniques
}
}
}
} }" }
'@
$Cloudflare_zone = Invoke-RestMethod -Method Post -Headers $Cloudflare_Oauth_Header -ContentType "application/json; charset=utf-8" -Uri $oAuth2TokenUrl -Body $query
而且我不断收到错误Invoke-RestMethod : The remote server returned an error: (501) Not Implemented.
但是如果我在 cmd 中卷曲它会返回预期的内容并且没有显示错误。
如果您需要更多详细信息,请告诉我。
解决方案
我建议先让一个简单的查询起作用,然后将其扩展为更复杂。此外,请务必使用-ContentType "application/json"
某些 GraphQL 服务器需要的。该开关-UseBasicParsing
还可以帮助避免错误,但可能不是这里的问题。最后,您可能还需要在 URL 中使用斜杠:例如http://127.0.0.1:8080/graphql/。
这个线程也可能有帮助: https ://www.reddit.com/r/PowerShell/comments/b9jasa/query_graphql_with_powershell/
推荐阅读
- javascript - 是否可以使用 ResizeObserver 来防止元素上的 Onclcik 事件
- python - 如何使用不同 Pandas df 中的值更改 Pandas df 中的值
- python - 线程功能后文件路径未保存
- ansible - 安西布尔。试图从字符串中获取 IP 地址的第三个八位字节以用作变量
- class - 主页面中的 UWP 调用方法
- typescript - .pdf 文件的 TypeScript 类型声明
- python - 使用 Json File 过滤单词列表
- c# - 我的数据库插入方法插入空值而不是填充值 C#
- python - Aws ses 错误:调用 SendBulkTemplatedEmail 操作时发生错误 (InvalidParameterValue)
- python - 为什么 numpy.arange() 和 range() 生成的相同数字的(复杂)函数不同?