Trouble with Invoke-WebRequest

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 5 years, 9 months ago.

  • Author
    Posts
  • #5408

    by kittH at 2013-01-07 08:07:36

    Hey guys, I'm trying to do some simple automation for rebooting a webserver, and I want to check a URL after reboot to make sure the website is available.

    The issue is that the webserver is normally behind a load balancer, and connecting directly to the server I get certificate errors:
    Invoke-WebRequest : The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

    I found a workaround for that online: [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

    but on subsequent attempts I receive the following error which I have not been able to resolve:
    Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.

    I am able to open the URL in IE and Firefox (with cert warnings) and I have been able to download it using wget if I ignore the certs. All I want to do is check if the page loads (look for the title or a link) but I am not able to get anything to come up.

    by kittH at 2013-01-07 13:57:40

    Well, I'm not sure why that didn't work but I've found a workaround by just calling the System.Net.Webclient directly...

    $WebClient = New-Object System.Net.WebClient
    [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
    $WebClient.DownloadString("https]

    returns what I need.

You must be logged in to reply to this topic.