【问题标题】:Powershell Invoke-RestMethod : The remote server returned an error: (413) Request Entity Too LargePowershell Invoke-RestMethod:远程服务器返回错误:(413)请求实体太大
【发布时间】:2021-02-22 23:20:53
【问题描述】:

这是我提出的“无法将 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

如何解决此错误?在编写上述脚本时,我可以采用更好的脚本语言和/或实践吗?

【问题讨论】:

  • 我可以知道你的 JSON 的大小吗?

标签: json azure powershell


【解决方案1】:

【讨论】:

    猜你喜欢
    • 2016-06-10
    • 1970-01-01
    • 1970-01-01
    • 2014-07-23
    • 2015-03-21
    • 2021-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多