根据文档,我应该将这两个值括在方括号内,但这似乎不起作用。
我的代码如下:
$params = @{
body = @{
"jsonrpc"= "2.0"
"method"= "item.get"
"params"= @{
"host"= $HostName
"search"= @{
"key_"= "[vm.memory.size[total],system.cpu.num]"
}
"searchByAny"= "true"
}
"id"= 50
"auth"="e57c8231e4d8f0f1c8d3ea2209299e65864a8c394458f670a9bc35583c19e129"
} | ConvertTo-Json
uri = "$baseurl/api_jsonrpc.php"
headers = @{"Content-Type" = "application/json"}
method = "Post"
}
$HostDetails = $($_.HostName)
$result = Invoke-WebRequest @params -useBasicParsing
$rawdata = $result | ConvertFrom-Json
#$rawdata.result
但它不起作用,它产生了以下结果-
StatusCode : 200
StatusDescription : OK
Content : {"jsonrpc":"2.0","result":[],"id":50}
RawContent : HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: POST
Access-Control-Max-Age: 1000
Strict-Transport-Security: max-age=315360...
Forms :
Headers : {[Access-Control-Allow-Origin, *], [Access-Control-Allow-Headers, Content-Type], [Access-Control-Allow-Methods,
POST], [Access-Control-Max-Age, 1000]...}
Images : {}
InputFields : {}
Links : {}
ParsedHtml :
RawContentLength : 37
我试着将行“key_”=....改为我上面所述的各种变体,但似乎没有产生任何结果,有些抛出错误。
1条答案
按热度按时间3pvhb19x1#
根据文档,我应该将这两个值括在方括号内
我非常怀疑--文档可能会说你需要提供一个 * 数组 * 的键,在JSON中是
[ "<key1>", "<key2>", ... ]
。在PowerShell中,您需要使用数组子表达式运算符:
一旦转换为JSON,它最终将看起来像
"key_":["vm.memory.size[total]", "system.cpu.name"]