【问题标题】:Post JSON reqeust to URL using powershell使用 powershell 将 JSON 请求发布到 URL
【发布时间】: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


【解决方案1】:

经过一番阅读发现我不见了| ConvertTo-Json - 最后一次关闭后的深度 4 } :)

【讨论】:

    猜你喜欢
    • 2011-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多