"Positional Parameter" 使用 cURL 发布数据时出错

"Positional Parameter" error when posting data with cURL

如果我在没有 --data "..." 的情况下发出命令,它工作得很好。我试过 Google 但找不到这个问题的任何答案。按照位于 here 的指示,当我尝试使用 cURL post 数据时出现以下错误:

PS C:\Users\David> curl --data "SMethod=0" "http://localhost/terra/modules/scripts/Query.php"
Invoke-WebRequest : A positional parameter cannot be found that accepts argument 'SMethod=0'.
At line:1 char:1
+ curl --data "SMethod=0" "http://localhost/terra/modules/scripts/Query.php"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

您的问题在这里得到解答:Running cURL on 64 bit Windows

你不是 运行 curl 你是 运行 一个叫做 Invoke-WebRequest 的东西,它的别名是 curl。您需要取消 curl 的别名,download 并安装 curl(如果您还没有)。

Remove-item alias:curl

这样容易卷曲!!

尝试和乐趣..而且 curl 可以制作你自己的 SHORTEN URL ,所以不需要与第 3 方合作.. :D

正如其他答案已经提到的,powershell 中的 curl 命令是 别名 并在后台使用 Invoke-WebRequest cmdlet。它具有与 curl 类似的功能。

您可以发出 POST 请求并发送和接收数据,而无需安装任何东西:

curl -body "SMethod=0" "http://localhost/terra/modules/scripts/Query.php" -Method 'POST'

选项 -body (Invoke-WebRequest) 等同于 -d--data (curl)。 HTTP Method 也必须指定。

这个Whosebug answer also considers New-WebServiceProxy and Invoke-RestMethod.

使用命令提示符而不是使用 PowerShell。

如果您使用的是 PowerShell,则需要在 curl 命令前加上前缀 cmd /c。例如:

cmd /c curl --data "SMethod=0" "http://localhost/terra/modules/scripts/Query.php"