windows - Windows curl 失败

标签 windows powershell curl

我在 unix 中执行 curl,效果很好。同样的 curl 在 Windows 中失败。

UNIX

curl -k --user admin:f1f82c270ec3ce28b4279809900fa00b -H "Jenkins-Crumb:3e7dc5a087ef7697f4a31d74fb99c4ac" -X POST https://jenkins-xyz/buildWithParameters?token=test\&release_version=2.1.0

在 windows powershell 中,同样的事情会出现以下错误

PS D:\Softwares\curl> curl.exe -k --user admin:f1f82c270ec3ce28b4279809900fa00b -H "Jenkins-Crumb:3e7dc5a087ef7697f4a31d
74fb99c4ac" -X POST https://jenkins-xyz/buildWithParameters?token=test\&release_version=2.1.0
At line:1 char:226
+ ... ers?token=test\&release_version=2.1.0
+                    ~
The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
quotation marks ("&") to pass it as part of a string.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : AmpersandNotAllowed

最佳答案

您需要在 PowerShell 的命令行中引用您的参数或使用命令运算符 (&)。它将您的符号解释为命令运算符。

& .\curl.exe -k --user admin:f1f82c270ec3ce28b4279809900fa00b -H "Jenkins-Crumb:3e7dc5a087ef7697f4a31d74fb99c4ac" -X POST https://jenkins-xyz/buildWithParameters?token=test\&release_version=2.1.0

powershell-and-external-commands-done-right

关于windows - Windows curl 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44659221/

相关文章:

c++ - 如何将 libcurl 与 Google Speech API 一起使用(--data-binary 或 --upload-file 的等价物是什么)?

c - 在 Windows 中使用 system() 或 popen() 调用 gcc 时出错

python - 如何在 Python 控制台程序中使用 echo "*"读取密码?

windows - 检测 C/C++ 中字符串的编码

powershell - 省略号在PowerShell中做什么?

PowerShell:重定向 mysqldump.exe 的错误

PHP 获取 URL 或页面的内容

php - 在Windows上安装elasticsearch

variables - PowerShell,如何增加变量名称?

php - 在 PHP 中使用 cURL 进行 RAW POST