【发布时间】:2021-08-05 01:43:42
【问题描述】:
我需要使用 powershell 将 json 请求发布到 url。 卷曲体长这样:
{
"records":
[ {
\"source\" : \"Pinger\",
\"node\" : \"nameofnode\",
\"type\" : \"ICMP\",
\"resource\" : \"C:\",
\"severity\" : \”0\",
\"description\" : \"No ping to host\",
}
] }
我正在尝试这个:
$jsonreqUP=@{
records= @(
@{
source="Pinger"
node= $i
type="ICMP"
resource="switch"
severity=0
description="No ping to host $i"
}
)
}
Invoke-RestMethod -Uri http://justasite.com/jsonv2 -Headers @{Authorization = "Basic $base64AuthInfo" } -Credential $creds -Method POST -Body $jsonreqUP -ContentType "application/json"
我收到错误:Invoke-RestMethod:远程服务器返回错误:(400) 错误请求。 $i 持有一个主机名变量。
我的转型有什么问题?
提前很多!
【问题讨论】:
-
您的资源参数不同。
-
Severity 是原始样本中的一个字符串,第二个是一个数字。
-
感谢您的 cmets。我清除了这两件事,但错误仍然存在。将不得不进一步检查。
标签: json powershell curl post servicenow