【问题标题】:Invoke-WebRequest : {"message":"Missing 'api-version' request header. Please set this header with the a value of a supported API versionInvoke-WebRequest : {"message":"缺少 'api-version' 请求标头。请将此标头设置为支持的 API 版本的值
【发布时间】:2020-05-02 22:06:17
【问题描述】:

我尝试在 Windows 中使用带有 powershell 的 Invoke-WebRequest 方法执行 API,但它返回以下消息:

Invoke-WebRequest : {"message":"缺少 'api-version' 请求标头。请将此标头设置为支持的 API 版本的值。支持的最低版本为 'v1'。最大 支持的版本是'v1'。"}

下面,这是我在请求中设置的:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$header = @{
    "X-ApiKeys" = "******2DD1-F002-7059-6138-*****2EEp7mEiWSG86QE="
    "X-Api-Version" = "1"
    "Content-Type" = "application/json"
    "Accept" = "application/json"
}
Invoke-WebRequest -Method Get -Headers $Header -Uri https://127.0.0.1:4119/api/computers?api-version=1

有人可以帮帮我吗?

提前致谢,

【问题讨论】:

  • 不只是要求像"api-version" = "v1"这样的标题吗?了解您正在使用的 API 以及特定调用的文档会有所帮助。
  • "X-Api-Version" = "1"改为"X-Api-Version" = "v1"
  • 我更改了这个参数它也解决了问题,非常感谢

标签: powershell invoke-webrequest


【解决方案1】:

要获得一致的帮助,最好准确说明您尝试联系的 API。看着端口,似乎是为 Deep Security 准备的。 错误消息告诉您标头中缺少“api-version”参数,幸运的是它还为您提供了预期值(v1)!

如果 API 对 Deep Sec 有效,您还必须在“api-secret-key”参数(而不是 X-ApiKeys)中设置您的密钥:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$header = @{
    "api-secret-key" = "<your secure key>"
    "api-version" = "v1"
    "Content-Type" = "application/json"
    "Accept" = "application/json"
}
Invoke-WebRequest -Method Get -Headers $Header -Uri https://127.0.0.1:4119/api/computers

【讨论】:

  • 您的回答解决了我的问题,非常感谢,
猜你喜欢
  • 1970-01-01
  • 2018-04-06
  • 1970-01-01
  • 2018-10-31
  • 2018-04-15
  • 1970-01-01
  • 1970-01-01
  • 2015-11-08
  • 2018-02-03
相关资源
最近更新 更多