【发布时间】: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-RestMethod或Invoke-WebRequest与-InFile参数一起使用。 -
我不是从文件中读取数据——只是内联 json 与
--data-binary一起发送 -
发送 JSON 正文会起作用吗?您可以使用
-Body参数。 -
-Body参数似乎不关心二进制或不按预期工作,尽管它确实需要特定的转义字符 - 感谢您的反馈!
标签: powershell curl invoke-webrequest