Invoke-RestMethod: The underlying connection was closed: An unexpected error occurred on a send

Occasional Visitor

While trying to use the Invoke-RestMethod, I am getting: The underlying connection was closed: An unexpected error occurred on a send.

I tried using [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12 before Invoke-RestMethod.

But, after adding this before Invoke-RestMethod I am getting RPC server is unavailable.

Any solution to this please?

1 Reply
Could you share a screenshot of the error and a part of the script with the invoke-resthmethod?