windows - powershell中的curl格式化

标签 windows powershell unix curl

我有一个在 Linux 系统上运行得非常好的curl。我只是使用一些参数远程触发 Jenkins 作业。

但是 Windows 中的相同命令会出错。

curl.exe -k --user abc:xyz -X POST https://myjenkins.com/job/abc/buildWithParameters??token=deploy\&release_version=2.3.1.0-5-auto2\&docker_registry=10.0.0.12:8083\&vcmts_build=vcmts_pi07

错误如下:

    At line:1 char:260
+ ... ??token=deploy\&release_version=2.3.1.0-5-auto2\&docker_registry=96.118.23.36:80 ...
+                    ~
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.
At line:1 char:293
+ ... .3.1.0-5-auto2\&docker_registry=10.0.0.12:8083\&vcmts_build=vcmts_pi07
+                    ~
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.
At line:1 char:328
+ ... 0.0.12:8083\&vcmts_build=vcmts_pi07
+                    ~
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

为了避免此问题,我应该做什么格式更改?

最佳答案

将参数括在单引号中,单引号不会像双引号字符串那样扩展。

curl -k --user 'abc:xyz' -X POST 'https://myjenkins.com/job/abc/buildWithParameters?token=deploy&release_version=2.3.1.0-5-auto2&docker_registry=10.0.0.12:8083&vcmts_build=vcmts_pi07'

关于windows - powershell中的curl格式化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45238669/

相关文章:

powershell - 如何在 PowerShell 中使用公共(public) IP 地址将 EC2 实例启动到 VPC?

java - 将java作为windows服务运行的简单灵活的方法

windows - 如何更改 ftp "network drives"的 Windows 7 默认 View ?

xml - 使用 Powershell 编辑子文件夹中的 zip 文件内容

mysql - Powershell - 插入 MySQL 数据库表错误?

java - 通过 Runtime.exec() 执行管道 ps unix 命令时出现问题

linux - 使用批处理文件杀死远程 Linux 机器中的进程

c++ - 简单的 Http 获取响应

html - 在 Windows 上调试 Ipad Web 应用程序

windows - 检查给定路径是否是特殊文件夹路径?