我想在使用invoke-restmethod/invoke-webrequest的powershell中執行REST API,但是當我傳遞Json時失敗投入。它與CURL命令一起使用。我想在powershell中使用invoke-restmethod/invoke-webrequest執行REST API,但是當我通過Json輸入時失敗
捲曲-v --user管理員:密碼-H接受:應用/ JSON -H內容類型:應用程序/ JSON -d 「@ C:\ DATA \ test.json」 -X POST http://10.11.60.88:8081/artifactory/api/distribute
Test.json內容如下
{
"targetRepo" : "ECSDigital_Bintray",
"packagesRepoPaths" : ["SNOW/org/apache/maven/maven-artifact/3.3.9/maven-artifact-3.3.9.jar"]
}
我書面方式下面PowerShell和它給了我一系列的錯誤。
$ USER = 「admin」 的
$傳球= 「密碼」
$ secpasswd =的ConvertTo-SecureString的$用戶-AsPlainText -Force $名氣=新物體System.Management.Automation.PSCredential ($ pass,$ secpasswd)
$ postParams = @ {targetRepo ='SNOW'; packagesRepoPaths ='[「org/apache/maven/maven-artifact/3.3.9/maven-artifact-3.3.9.jar 「]'}
Invoke-WebRequest -Uri」http://10.11.60.88:8081/artifactory/api/distribute 「-Credential $ cred -Method Post -ContentType」application/json「-Body $ postParams
錯誤:Invoke-WebRequest:遠程服務器返回錯誤:(400)錯誤的請求。
我試過一些json輸入的組合,但沒有去。任何幫助?