[英]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. 我搜索过高低,并在产品论坛上询问,但似乎无法解决这个问题。
Using PowerShell 5 I'm attempting to limit my results by using a range header in the way the API documentation indicates. 使用PowerShell 5我试图通过API文档指示的方式使用范围标题来限制我的结果。 However, I receive the following error when I try to use it.
但是,当我尝试使用它时,我收到以下错误。
"The 'RANGE' header must be modified using the appropriate property or method. Parameter name: name"
“必须使用适当的属性或方法修改'RANGE'标头。参数名称:name”
I've tried: 我试过了:
$headers = @{
SEC= $apiKey
range="items=0-49"
}
$result = Invoke-RestMethod -Method get -Uri $global:URI -ContentType 'application/json' -Header $headers
and... 和...
$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
Also, here's the curl example given within the API documentation: 另外,这是API文档中给出的curl示例:
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'范围:items = 0-49'-H'版本:10.0'-H'接受:application / json''https: //product.com/api/s/of “
Really appreciate any pointers on this. 真的很感激任何指针。
Thanks in advance 提前致谢
It seems to be a bug in PowerShell. 它似乎是PowerShell中的一个错误。 I found this blog page: https://sethjackson.github.io/2017/01/18/header-woes/
我找到了这个博客页面: 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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.