![](/img/trans.png)
[英]powershell.exe : Invoke-RestMethod : The remote server returned an error: (406) Not Acceptable
[英]Powershell Invoke-RestMethod : The remote server returned an error: (413) Request Entity Too Large
这是我提出的“无法将 JSON 数据摄取到 Azure 事件中心”问题的延续。
我编写了下面的 powershell 脚本来从 API 端点获取 JSON 数据,然后将这些数据在没有任何格式更改的情况下移动到 Azure 事件中心。 当我运行它时,我收到以下错误:
$url = "https://data.melbourne.vic.gov.au/resource/vh2v-4nfs"
$apptoken = "n8lQcUZROasdh9fSSMuV"
# Set header to accept JSON
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Accept","application/json")
$headers.Add("X-App-Token",$apptoken)
$results = Invoke-RestMethod -Uri $url -Method get -Headers $headers
$resultsJSON = $results | ConvertTo-Json
#Write-Host $results
$method = "POST"
$URI = "https://EHNS.servicebus.windows.net/eh-streetparking/messages"
$signature = "SharedAccessSignature sr=EH.servicebus.windows.net%2feh-streetparking&sig=erTfoeVLiWrOk9aDsU%3d&se=1605994&skn=eh-sap-streetparking"
# API headers
$headers = @{
"Authorization"=$signature;
# "Content-Type"="application/json;type=entry;charset=utf-8";
"Content-Type"="application/json";
}
# create Request Body
# execute the Azure REST API
Invoke-RestMethod -Uri $URI -Method $method -Headers $headers -Body $resultsJSON
#错误
Invoke-RestMethod : The remote server returned an error: (413) Request Entity Too Large.
At C:\Users\User1 - \Scripts\get_mel_streetparking_data.ps1:37 char:1
+ Invoke-RestMethod -Uri $URI -Method $method -Headers $headers -Body $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
如何解决此错误? 在编写上述类型的脚本时,我可以采用什么更好的脚本语言和/或实践?
请注意,对于服务总线, 最大消息大小:标准层为 256 KB,高级层为 1 MB。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.