使用powershell将JSON请求发布到URL
我需要使用powershell将json请求发布到url。 卷曲体如下所示:使用powershell将JSON请求发布到URL,json,powershell,curl,post,servicenow,Json,Powershell,Curl,Post,Servicenow,我需要使用powershell将json请求发布到url。 卷曲体如下所示: { "records": [ { \"source\" : \"Pinger\", \"node\" : \"nameofnode\", \"type\" : \"ICMP\", \"resource\" : \"C:
{
"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包含一个hostname变量
我的转换有什么问题
提前很多次 经过一些阅读,发现我缺少| ConvertTo Json-Depth 4在最后一次closng之后:)您的资源参数不同。严重性是原始示例中的一个字符串,第二个示例中的一个数字。感谢您的评论。我把这两件事都清除了,但错误依然存在。我们需要进一步检查。