嗨,有人可以告诉我我要去哪里了,我从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
最佳答案
默认的http动词是GET,不允许正文/有效负载。将POST作为方法参数传递,并且不要自己对json序列化主体。
关于json - 从Powershell发布到JSON Rest API,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50547728/