【问题标题】:"Positional Parameter" error when posting data with cURL使用 cURL 发布数据时出现“位置参数”错误
【发布时间】:2015-03-23 14:44:50
【问题描述】:

如果我要发出没有--data "..." 的命令,它就可以正常工作。我试过谷歌,我找不到这个问题的任何答案。按照位于here 的指示,当我尝试使用 cURL 发布数据时出现以下错误:

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

【问题讨论】:

    标签: php curl http-post


    【解决方案1】:

    正如其他答案已经提到的,powershell 中的 curl 命令是 aliased 并在后台使用 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 也必须指定。

    这个StackOverflow answer 也考虑New-WebServiceProxyInvoke-RestMethod

    【讨论】:

      【解决方案2】:

      Remove-item alias:curl

      这会很容易卷曲!

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

      【讨论】:

        【解决方案3】:

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

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

        【讨论】:

          猜你喜欢
          • 2014-09-15
          • 2012-12-08
          • 1970-01-01
          • 2017-06-12
          • 1970-01-01
          • 1970-01-01
          • 2019-02-24
          • 1970-01-01
          • 2015-09-27
          相关资源
          最近更新 更多