【发布时间】:2021-09-28 21:57:12
【问题描述】:
我正在尝试通过 PowerShell 中的 cURL 发送 HTML 请求。有问题的代码:
$command = 'curl -d @request.txt -o testoutput.xml -X "POST" -H @header.txt -u "username:password" "URL"'
Invoke-Expression $command
HTML 正文 (-d) 和标头 (-H) 需要从文件中读取,因此文件名前有 @。
为了使其正常工作,我需要转义 @ 以便 PowerShell 不会将其解释为 splat 运算符 - 这是我的问题,到目前为止我没有尝试过任何工作:
- 用单引号括起来
- 这里是文档 (@" "@)
- 这里是字符串(@''@)
- 使用带占位符的字符串模板 ("{0}request.txt" -f "@")
- Unicode 转义(“`u{0040}request.txt”)
如何正确转义 @?还是我完全走错了路? (抱歉,我是 PowerShell 新手)
【问题讨论】:
-
使用
--%:curl --% -d @request.txt -o testoutput.xml -X "POST" -H @header.txt -u "username:password" "URL"- 这将阻止 PowerShell 解析器尝试评估其后的任何内容
标签: powershell curl escaping