Why are my API calls through Powershell failing with "Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send."?
search cancel

Why are my API calls through Powershell failing with "Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send."?

book

Article ID: 282731

calendar_today

Updated On: 08-04-2020

Products

CloudHealth

Issue/Introduction

This may be a TLS negotiation issue in Powershell. 

A possible fix is to allow TLS, TLS 1.1 and TLS 1.2 by adding the following before the request:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12

For more information, see:
https://blog.darrenjrobinson.com/powershell-the-underlying-connection-was-closed-an-unexpected-error-occurred-on-a-send/