简体   繁体   English

Powershell Invoke-RestMethod:远程服务器返回错误:(413) 请求实体太大

[英]Powershell Invoke-RestMethod : The remote server returned an error: (413) Request Entity Too Large

This is in continuation to "Unable to ingest JSON data into Azure Event Hub" issue raised by me.这是我提出的“无法将 JSON 数据摄取到 Azure 事件中心”问题的延续。

I wrote the below powershell script to get the JSON data from an API endpoint and then move this data without any format change to Azure Event Hub.我编写了下面的 powershell 脚本来从 API 端点获取 JSON 数据,然后将这些数据在没有任何格式更改的情况下移动到 Azure 事件中心。 When I run this I am getting the below error:当我运行它时,我收到以下错误:

$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


#Error #错误

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

How do I resolve this error?如何解决此错误? Are there any better scripting language and/or practices which I can adopt while writing above sort of scripts?在编写上述类型的脚本时,我可以采用什么更好的脚本语言和/或实践?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM