Sas*_*iev 7 powershell json httprequest azure
我正在尝试从 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
Run Code Online (Sandbox Code Playgroud)
我的脚本的第 43 行看起来像这样
Invoke-RestMethod -uri $uriHangouts -Method Post -body $body -ContentType 'application/json'
Run Code Online (Sandbox Code Playgroud)
其中 $uriHangouts 是 webhook 地址,$body 是根据此处提供的架构的消息: https: //developers.google.com/hangouts/chat/reference/message-formats/basic
由于它只是测试,我每次都会发送完全相同的消息。这是一个带有一些标记的基本版本。如果我将其转发到 Azure 逻辑应用程序并将其从那里重新发送到环聊,则每次都能正常工作。如果我从我的电脑发送它,它每次也能正常工作。到目前为止,我尝试使用 Invoke-WebRequest 而不是 Invoke-RestMethod,并使用以下行强制 TLS 1.2 (1.1),但没有成功:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Run Code Online (Sandbox Code Playgroud)
我真的不知道下一步该去哪里。
请帮忙!先感谢您!
| 归档时间: |
|
| 查看次数: |
33185 次 |
| 最近记录: |