【发布时间】:2021-05-09 01:40:57
【问题描述】:
我正在尝试从 Azure Powershell Runbook 将 Microsoft Azure 警报发送到 Google 聊天室(环聊)。有时会发送消息没有任何问题,但大约有一半的尝试返回以下错误:
Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a receive.
At line:43 char:1
+ Invoke-RestMethod -uri $uriHangouts -Method Post -body $body -Content ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
我的脚本的第 43 行如下所示
Invoke-RestMethod -uri $uriHangouts -Method Post -body $body -ContentType 'application/json'
根据此处提供的架构,其中 $uriHangouts 是 webhook 地址,$body 是消息: https://developers.google.com/hangouts/chat/reference/message-formats/basic
由于它只是测试,我每次都发送完全相同的消息。这是一个带有一些标记的基本版本。 如果我将它转发到 Azure Logic App 并从那里重新发送到环聊,它每次都能正常工作。 如果我从我的 PC 发送它,它每次都可以正常工作。 到目前为止,我尝试使用 Invoke-WebRequest 代替 Invoke-RestMethod,但没有成功,并使用以下行强制 TLS 1.2 (1.1):
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
我真的不知道下一步该去哪里。
请帮忙! 提前谢谢!
【问题讨论】:
标签: json azure powershell httprequest