Windows: Invoke-RestMethod =>The underlying connection was closed: An unexpected error occurred on a receive.

Hi,

Invoke-RestMethod or Invoke-WebRequest uses by default TLS 1.0. This protocal is outdated and would be not accepted by the most Webservers anymore.

Usually this results in the following error message:
The underlying connection was closed: An unexpected error occurred on a receive.

Solution: Set the protocol version before calling those command-lets.

PS D:\> [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
PS D:\> Invoke-RestMethod -Method "GET" -Uri "https://myHOst.myDomain.org/v1/myAPICall" -Headers $headers

Michael

Advertisment to support michlstechblog.info

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.