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