我已經在論壇上看到了許多變體,但沒有一個對我有用,任何人都可以用正確的 curl -d 語法來啟發我,以使命令正常作業(從 $variable_json 正確獲取資料)?將文本從變數直接放入 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":"此欄位為必填項","errorMessageCode":"CONSOLE_FORMS_FIELD_REQUIRED"}],"category":[{"error":"此欄位為必填項","errorMessageCode":" CONSOLE_FORMS_FIELD_REQUIRED"}],"customDomains":[{"error":"此欄位為必填項","errorMessageCode":"CONSOLE_FORMS_FIELD_REQUIRED"}],"note":[{"error":"此欄位為必填項"," errorMessageCode":"CONSOLE_FORMS_FIELD_REQUIRED"}],"hostingPlatform":[{"error":"此欄位為必填項","errorMessageCode":"CONSOLE_FORMS_FIELD_REQUIRED"}],"score":[{"error":"此欄位為必需","errorMessageCode":"CONSOLE_FORMS_FIELD_REQUIRED"}],"錯誤":true}
這很奇怪,因為如果我手動輸入 json 檔案中的資料,它就可以正常作業。我的整個問題是該命令無法正確決議“-d pamater”的變數/file.json
uj5u.com熱心網友回復:
我只是放棄了這個問題并讓微軟Lv3去做。
他們正在使用帶有一些 @[Ordered] json 正文的 cmdlet....廢話我從未見過
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/459359.html
