6
votes

When I try to use Invoke-WebRequest on https ,I'm getting some weird error:

"Invoke-WebRequest : The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."

It's My Code:

   [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls
    $url = "https://X.X.X.X:4343/officescan/console/html/cgi/cgiChkMasterPwd.exe"
    $r = Invoke-WebRequest $url -SessionVariable office

Any advice for me ?? Thanks a lot.

1
See the accepted answer: stackoverflow.com/a/15841856/934946Sage Pourpre
Basically, if your SSL certificate is invalid or self-signed, you will have this error but you can "trust" all SSL certificate for your script so the error won't appear.Sage Pourpre
@SagePourpre , thank your advice, it's work ^^Scott Lee

1 Answers

-2
votes

You can also get that problem if you're using https:// in the Uri and the url is available through http://. More specifically, use

Invoke-WebRequest -Uri 'https://trees.com/'

and will get the following error

Invoke-WebRequest : The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

It doesn't work

Then, if you use

Invoke-WebRequest -Uri 'trees.com'

or if you use

Invoke-WebRequest -Uri 'http://trees.com'

will work fine

It works