Powershell Invoke-RestMethod: il server remoto ha restituito un errore: (413) Request Entity Too Large

Nov 10 2020

Questo è in continuazione al problema "Impossibile inserire dati JSON nell'hub eventi di Azure" sollevato da me.

Ho scritto lo script PowerShell riportato di seguito per ottenere i dati JSON da un endpoint API e quindi spostare questi dati senza alcuna modifica di formato nell'hub eventi di Azure. Quando lo eseguo ricevo il seguente errore:

$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


#Errore

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

Come risolvo questo errore? Esistono linguaggi e / o pratiche di scripting migliori che posso adottare durante la scrittura di una sorta di script sopra?

Risposte

singhh-msft Nov 12 2020 at 07:12

Tieni presente che per il bus di servizio, dimensione massima del messaggio: 256 KB per il livello Standard, 1 MB per il livello Premium.