【发布时间】:2018-05-18 22:14:21
【问题描述】:
请问如何使用 Powershell 进行此 PUT 调用?我正在使用 Powershell 5。
【问题讨论】:
标签: rest powershell urbancode
请问如何使用 Powershell 进行此 PUT 调用?我正在使用 Powershell 5。
【问题讨论】:
标签: rest powershell urbancode
我在尝试做同样的事情时遇到了这篇文章。对我来说,问题在于知道究竟正确的 URL 是什么(参见 Adam Parsons 的回答):
$URL = "url-goes-here"
经过 大量 搜索(IBM 的文档在这方面的努力并不值得),我能够通过在 Chrome 开发人员工具中观察流量来识别正确的 URL(感谢 Darrell Schrag 的博客帖子:https://drschrag.wordpress.com/2013/10/03/the-udeploy-rest-api)。
对于那些搜索这个的人,我的 PowerShell REST 调用序列现在看起来像这样(并且成功执行):
$tokenEncoded = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes( "PasswordIsAuthToken:{"token":"$authToken"}" ))
$headers = @{Authorization = "Basic "+$tokenEncoded}
# 1. Get component version ID
$uri = "$uDeployServer:8443/cli/version/getVersionId`?component=$componentName&version=$versionName"
$versionId=Invoke-RestMethod -Uri $uri -Method GET -Headers $headers
# 2. Add component version status
$uri = "$uDeployServer:8443/rest/deploy/version/$versionId/status/$versionStatus"
Invoke-RestMethod -Uri $uri -Method PUT -Headers $headers
【讨论】:
大概是这样的……
$Hash = @{
Component="StringValue"
Version="StringValue"
Status="StringValue"
}
$Json = $Hash | ConvertTo-Json
$URL = "url-goes-here"
$Cred = Get-Credential
Invoke-RestMethod -Method "POST" -Uri $url -Credential $Cred -Body $Json