![](/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.