我在azure devops版本中添加了powershell脚本,并尝试使用带有授权 token 和xml文件的Invoke-WebRequest发送POST请求。
我究竟做错了什么?
我从另一个POST请求中获得了授权 token ,并尝试使用此 token 创建 header ,并尝试使用X射线端点发送xml文件(NUnit XML结果-POST / api / v1 / import / execution / nunit)
https://confluence.xpand-it.com/display/XRAYCLOUD/Import+Execution+Results+-+REST#ImportExecutionResults-REST-NUnitXMLresults
授权 token ,例如 header 参数
内容类型(如Powershell参数)
$bodyForAuth=@{"client_id"="...";
"client_secret"="...";
}
$jsonAuth=Invoke-WebRequest -Uri $urlForAuth -Method POST -Body ($bodyForAuth|ConvertTo-Json) -ContentType "application/json"
$authToken=ConvertFrom-Json -InputObject $jsonAuth
$headers=@{ Authorization = "Bearer $authToken" }
Invoke-WebRequest -Headers $headers -Uri $urlForXrayApi -Method POST -ContentType "text/xml" -InFile $TestResultsXmlPath
我有错误:“Invoke-RestMethod:找不到请求中的身份验证数据”
我也尝试这样发送:
$headers=@{ Authorization = "Bearer $authToken";"Content-Type"="text/xml" }
Invoke-WebRequest -Headers $headers -Uri $urlForXrayApi -Method POST -InFile $TestResultsXmlPath
而且也有同样的错误:
"Invoke-RestMethod : Could not find authentication data on request"
但是,如果我发送这样的POST请求(没有Content-Type):
$bodyForAuth=@{"client_id"="...";
"client_secret"="...";
}
$jsonAuth=Invoke-WebRequest -Uri $urlForAuth -Method POST -Body ($bodyForAuth|ConvertTo-Json) -ContentType "application/json"
$authToken=ConvertFrom-Json -InputObject $jsonAuth
$headers=@{ Authorization = "Bearer $authToken" }
Invoke-WebRequest -Headers $headers -Uri $urlForXrayApi -Method POST -InFile $TestResultsXmlPath
我有伺服器错误:
"Invoke-RestMethod : {"error":"Missing data in the nunit results import request"}"
Power Shell v.5.1
为什么当我发送到 header 服务器时无法对授权数据进行罚款?
最佳答案
我在请求中错过了“(”和“)”Invoke-WebRequest -Headers $headers -Uri $urlForXrayApi -Method POST -InFile $TestResultsXmlPath
应该Invoke-WebRequest -Headers $headers -Uri $urlForXrayApi -Method POST -InFile $(TestResultsXmlPath)
将$TestResultsXmlPath
更改为$(TestResultsXmlPath)
关于powershell - Invoke-RestMethod:发送到 header 时,无法根据请求找到身份验证数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56610057/