如何将变量或 json 文件提供给 curl

how to feed variable or json file to curl

我已经在论坛上看到很多变体,但 none 对我有用,任何人都可以用正确的 curl -d 语法启发我使命令正常工作(从 $[=29 正确获取数据=])?将变量中的文本直接放入 curl 中是没有问题的,但是对于变量它会出错。此变量根据以下模式动态组成,并且必须能够通过变量或 json 文件调用 curl -d。

$variable_json = '{\"customDomains\":[\"internal.test10.com\",\"external.test10.com\"],\"aadInfo\":{\"loginUrl\":\"https://developer.microsoft.com/en-us/graph/graph-explorer\"},\"name\":\"App-Test10\",\"category\":\"SAASDB_CATEGORY_COLLABORATION\",\"hostingPlatform\":2,\"score\":5,\"note\":\"This app was added by myself through API\",\"suffixSupport\":true,\"domains\":[],\"ipv4\":[],\"ipv6\":[],\"isCustomApp\":true}'

< $variable_json 已经用 ' 和 " 括起来转义了,至于上面的变量就是需要的最终输出 >

curl -L -X POST 'https://company_domain.portal.cloudappsecurity.com/api/v1/discovery/app_catalog/create_custom_app/' -H "Authorization: Bearer $Token" -H 'Content-Type: application/json' -d "$variable_json"

or

curl -L -X POST 'https://company_domain.portal.cloudappsecurity.com/api/v1/discovery/app_catalog/create_custom_app/' -H "Authorization: Bearer $Token" -H 'Content-Type: application/json' -d '@C:\Users\Administrator\Desktop\the_file.json'

答案可以是 unix 或 powershell,任何变体都可以。

谢谢

编辑:

收到的错误是:

{"name":[{"error":"This field is required","errorMessageCode":"CONSOLE_FORMS_FIELD_REQUIRED"}],"category":[{"error":"This field is required","errorMessageCode":"CONSOLE_FORMS_FIELD_REQUIRED"}],"customDomains":[{"error":"This field is required","errorMessageCode":"CONSOLE_FORMS_FIELD_REQUIRED"}],"note":[{"error":"This field is required","errorMessageCode":"CONSOLE_FORMS_FIELD_REQUIRED"}],"hostingPlatform":[{"error":"This field is required","errorMessageCode":"CONSOLE_FORMS_FIELD_REQUIRED"}],"score":[{"error":"This field is required","errorMessageCode":"CONSOLE_FORMS_FIELD_REQUIRED"}],"error":true}

这很奇怪,因为如果我手动从 json 文件中输入数据,它就可以正常工作。我的整个问题是该命令无法正确解析“-d pamater”

的 variable/file.json

我只是放弃了这个问题,让微软Lv3来做。

他们在一些@[Ordered] json body 中使用 cmdlets...我从未见过的废话