简体   繁体   English

范围标题必须使用适当的属性或方法

[英]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.

相关问题 New-AzureRmDataLakeStoreItem'User-Agent'标头必须修改错误 - New-AzureRmDataLakeStoreItem 'User-Agent' header must be modified error 在条件中使用表达式/属性 - Use expression/property in a condition 将方法设置为 Powershell 中 object 的属性 - Set method as property of object in Powershell 安装适当的 nuget 包后无法在 PowerShell 中使用程序集 - Can't use assembly in PowerShell after I've installed the appropriate nuget package Import-CSV 将 header 行作为单个属性输出 - Import-CSV outputs the header row as a single property 如何通过Powershell从文件头获取sql minsize属性? - how to get sql minsize property from file header via powershell? Add-AzureAccount:索引超出范围。 必须是非负数且小于集合的大小 - Add-AzureAccount : Index was out of range. Must be a non-negative and less than the size of the collection Excel Automation中的Powershell和方法/属性异常 - powershell and method/property exceptions in excel automation 使用PowerShell对带有标题的Excel列进行排序 - Use powershell to sort an excel column with header 有没有办法为Powershell版本5的InvokeRest方法获取Response标头 - Is there a way to fetch Response header for InvokeRest Method of Powershell Version 5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM