无法为命令 curl 绑定参数 'headers'

Cannot bind parameter 'headers' for command curl

我正在尝试将 curl 命令与下面的行一起使用,但遇到错误。

curl -H "Content-Type: application/json" -X POST -d '{"name": "ggg","address":"gemany" }'  urlplaceholder
Invoke-WebRequest : Cannot bind parameter 'Headers'. Cannot convert the "Content-Type: application/json" value of type "System.String" to type "System.Collections.IDictionary".
At line:1 char:9
+ curl -H "Content-Type: application/json" -X POST -d '{"name": "ggg"," ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

我可以说您正在使用 Microsoft Power shell 实用程序..它具有不同的语法。它期望 headers

的散列 table 类型值
@{<name> = <value>; [name = <value> ] ...}

如果您真的希望它在 power shell 中工作,请仔细阅读 power shell 的 Invoke-WebRequest 语法

当我在 curl 中 运行 这个命令时,它起作用了,没有问题。

一个调整是,如果您在 windows 中安装了 git,您可以将命令提示符设置为 Git\mingw64\bin,然后从那里执行您的 curl 命令