通过Invoke-RestMethod发送参数时出错

时间:2019-07-02 18:42:48

标签: powershell api

因此,我正在尝试创建一个新帐户并将其发送到数据库。但是,我不确定是否对对象'newaccount'的格式有误或在Invoke-RestMethod中的调用方式有误。

在尝试了所有方法后,我仍然收到错误“ 403禁止的请求”

newaccount = @{
    account = @{
        safeName = $safeName
        platformID = $platformID
        Address = $FQDN
        AccountName = $AccountNam;
        secret = "pass123"
        SecretID = $username
        AutoMgmt = "false"
        AutoMgmtReason = "N/A"
            }
}
$newaccount = $newaccount | ConvertTo-Json;
$auth = @{
    authenticaion=$seckey
    'Content-Type'=$contentType
    }
try{
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$Response2 = Invoke-RestMethod -Uri https://$url -Method post -Headers $auth -ContentType $contentType -Body $newaccount 

}catch [Exception]{
$ErrorMsg = $Error[0].Exception.Message;
Write-Error "Failed to Logon with $username. Error message: $ErrorMsg.";

C:\Users\"user"\Desktop\Uploadv6.9.6.ps1 : Failed to Logon with $creds. Error message: The remote server returned
an error: (403) Forbidden..
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Uploadv6.9.6.ps1

0 个答案:

没有答案