【问题标题】:Postman and VSTS Inline Powershell return different valuesPostman 和 VSTS Inline Powershell 返回不同的值
【发布时间】:2017-10-02 10:13:03
【问题描述】:

我正在 VSTS 和 Postman 中运行查询。在 Postman 中,我使用基本身份验证并输入了我的用户名和密码。在 VSTS 中,我使用内联 Azure Powershell 步骤。 VSTS 代码:

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))

Invoke-RestMethod -Method Get -Uri $Uri -ContentType "application/json; charset=utf-8; api-version=4.0-preview.4" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}

在 VSTS 中运行查询后,我写入输出 $uri 并将其复制到 Postman。在 Postman 查询的正文中,我得到 "count": "1" 和我期望的值。在 VSTS 中,使用完全相同的查询,我得到“count”:“0”。是什么导致了差异?

有时,我得到相同的数据而不是“计数”的差异,但它不可见。在 VSTS 中,它将是“{@{id=532; name=TestBuild_2017.09.28...”,在 Postman 中,它将显示所有数据,如“id”、“name”和“createdOn”。我可以更改它在 VSTS 中的查看方式以使其全部可见吗?

Uri 是:https://xx.vsrm.visualstudio.com/xx/xx/_apis/release/releases?api-version=4.0-preview.4&statusFilter=successful&$top=1&searchText=xx

【问题讨论】:

  • 您是在“在 VSTS”中运行它是什么意思?作为扩展的一部分?在构建或部署期间?
  • 作为内联 Azure Powershell 作为构建步骤。也更新了帖子描述。
  • 实际的 REST API ($Uri) 是什么?您使用的是同一个帐户吗?
  • 我用 Uri 更新了帖子
  • 你用我的解决方案解决了这个问题吗?

标签: rest postman azure-devops-rest-api


【解决方案1】:

原因是$字符是PowerShell中的关键字,需要使用grave-accent `转义。

改用https://xx.vsrm.visualstudio.com/xx/xx/_apis/release/releases?api-version=4.0-preview.4&statusFilter=successful&`$top=1&searchText=xx。

【讨论】:

    猜你喜欢
    • 2019-06-17
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多