范围标题必须使用适当的属性或方法 [英] Range Header Must Use Appropriate Property or Method
问题描述
我在产品论坛上进行了高低搜索和询问,但似乎无法弄清楚这一点.
I've searched high and low and asked on the product forums, but cannot seem to figure this out.
使用 PowerShell 5 我试图按照 API 文档指示的方式使用范围标头来限制我的结果.但是,当我尝试使用它时收到以下错误.
Using PowerShell 5 I'm attempting to limit my results by using a range header in the way the API documentation indicates. However, I receive the following error when I try to use it.
"必须使用适当的属性修改 'RANGE' 标头或方法.参数名称:name"
"The 'RANGE' header must be modified using the appropriate property or method. Parameter name: name"
我试过了:
$headers = @{
SEC= $apiKey
range="items=0-49"
}
$result = Invoke-RestMethod -Method get -Uri $global:URI -ContentType 'application/json' -Header $headers
还有……
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Accept','Application/Json')
$headers.Add('RANGE','items=0-49')
$headers.Add('SEC',$ApiKey)
$result = Invoke-WebRequest -Uri $global:URI -Headers $headers -Method get
此外,这里是 API 文档中给出的 curl 示例:
Also, here's the curl example given within the API documentation:
curl -s -X GET -u USERNAME -H 'Range: items=0-49' -H 'Version: 10.0' -H 'Accept: application/json' 'https://product.com/api/s/of'
curl -s -X GET -u USERNAME -H 'Range: items=0-49' -H 'Version: 10.0' -H 'Accept: application/json' 'https://product.com/api/s/of'
非常感谢您对此的任何指点.
Really appreciate any pointers on this.
提前致谢
推荐答案
这似乎是 PowerShell 中的一个错误.我找到了这个博客页面:https://sethjackson.github.io/2017/01/18/header-woes/
It seems to be a bug in PowerShell. I found this blog page: https://sethjackson.github.io/2017/01/18/header-woes/
根据此页面的解决方法:
The workaround according to this page:
$request = [System.Net.WebRequest]::Create($uri)
$request.Method = "GET"
$request.Headers.Add("SEC", $apiKey)
# add range header
$request.AddRange("items", 0, $count)
$reader = New-Object System.IO.StreamReader($request.GetResponse().GetResponseStream())
$data = ConvertFrom-Json $reader.ReadToEnd()
这篇关于范围标题必须使用适当的属性或方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!