The underlying connection was closed
For the past weeks I’ve used PowerShell to test REST APIs exposed over HTTPS. Everything was wonderful until I had to execute my script against a local instance of the service. My machine is not setup with proper certificates and PowerShell doesn’t see to like that. When ever I execute an Invoke-RestMethod command I get the following error message:
The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel
Looking around I was fortunate to find this one-liner that fixes everything!
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
By turning off certificate validation you are disabling security. Beware that this one-liner is a patch, and should not be used for anything else than development purposes.