【发布时间】:2018-05-27 08:02:32
【问题描述】:
您好,谁能告诉我这里哪里出错了,我从 powershell 执行 API 调用时收到以下错误。我尝试了多种方式格式化正文,但无法使其正常工作。
Invoke-RestMEthod : Cannot send a content-body with this verb-type.
At line:7 char:20
+ ... sponseKan = Invoke-RestMEthod -Uri $kanboardserver -ContentType "app ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-RestMethod], ProtocolViolationException
+ FullyQualifiedErrorId : System.Net.ProtocolViolationException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
我的代码;
$headersKan = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" -ErrorAction Stop
$headersKan.Add("X-API-Auth", "jsonrpc:$kanboardtoken")
$bodyKan = @{jsonrpc = "2.0"
id = "1"
method = "getAllProjects"
} | ConvertTo-Json
$responseKan = Invoke-RestMEthod -Uri $kanboardserver -ContentType "application/json" -Headers $headersKan -Body $bodyKan -ErrorAction Stop
Write-Host $responseKan
【问题讨论】:
-
您没有在帖子中显示所有相关代码。您有未定义且未在帖子中使用的变量,以及未定义且未在帖子中使用的变量。例如:“jsonrpc:$kanboardtoken”和$kanboardserver。
标签: json api powershell