【问题标题】:curl --data-binary in PowerShellPowerShell 中的 curl --data-binary
【发布时间】:2018-10-02 18:49:42
【问题描述】:

如果我有一个curl 命令,例如:

curl <url> \
  -H 'Content-Type: application/json' \
  -H 'API-Key: <key>' \
  --data-binary '{"blah":"blah {\n  blah2(accountId: id, integrations: {int1: {Vms: [{Id: id2, resourceGroups: [\"test1\", \"test2\", \"test3\"]}]}}) {\n    integrations {\n      id\n      name\n      service {\n        id\n        slug\n      }\n    }\n  }\n}\n", "variables":""}'

Powershell 中的--data-binary 等价于什么?一些答案说只是运行curl.exe,其他人提到改变内容类型。不过,这确实可以作为 shell 脚本正常工作。只是想知道是否可以将其转换为在 Powershell 中使用 Invoke-WebRequest

【问题讨论】:

  • Invoke-RestMethodInvoke-WebRequest-InFile 参数一起使用。
  • 我不是从文件中读取数据——只是内联 json 与 --data-binary 一起发送
  • 发送 JSON 正文会起作用吗?您可以使用-Body 参数。
  • -Body 参数似乎不关心二进制或不按预期工作,尽管它确实需要特定的转义字符 - 感谢您的反馈!

标签: powershell curl invoke-webrequest


【解决方案1】:

-body 参数与有效载荷一起使用

【讨论】:

  • 请详细说明这一点,以帮助未来的读者,包括解释您必须使用哪些特定的转义字符。
猜你喜欢
  • 2019-02-16
  • 1970-01-01
  • 2013-07-14
  • 2015-01-16
  • 2017-06-24
  • 2019-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多