【发布时间】:2020-11-05 05:09:47
【问题描述】:
在将 post rest api 调用发送到 scom 服务器时,我无法确定正文中的 json 正文下应该包含什么内容。我尝试了以下方法。
{
"credentials":"<base64 coded text of credential>"
}
这是我尝试更改为 postmain 请求的 powershell 脚本 rest api 请求
$server="servername"
# authentication part
$scomHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$scomHeaders.Add('Content-Type','application/json; charset=utf-8')
$bodyraw = "Windows"
$Bytes = [System.Text.Encoding]::UTF8.GetBytes($bodyraw)
$EncodedText =[Convert]::ToBase64String($Bytes)
$jsonbody = $EncodedText | ConvertTo-Json
$uri = "http:// $server/OperationsManager/authenticate"
$username = "username.com"
$password = ConvertTo-SecureString "paswword" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList ($username, $password)
$Request = Invoke-WebRequest `
-Method POST `
-Uri $uri `
-Headers $scomHeaders `
-body $jsonbody `
-Credential $cred `
-SessionVariable 'websession'
我还尝试使用I want to fetch the SCOM alerts data. But I keep getting the error 401. I am passing the credentials right 帖子的帮助。还是想不通。
【问题讨论】:
标签: scom