嗨,有人可以告诉我这里我出错了,从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
答案 0 :(得分:2)
默认的http动词是GET,它不允许正文/有效负载。将POST作为方法参数传递,不要自己json序列化身体。