Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用powershell将JSON请求发布到URL_Json_Powershell_Curl_Post_Servicenow - Fatal编程技术网

使用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:

我需要使用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包含一个hostname变量

我的转换有什么问题


提前很多次

经过一些阅读,发现我缺少| ConvertTo Json-Depth 4在最后一次closng之后:)

您的资源参数不同。严重性是原始示例中的一个字符串,第二个示例中的一个数字。感谢您的评论。我把这两件事都清除了,但错误依然存在。我们需要进一步检查。