# Trouble with Invoke-WebRequest

**URL:** <https://forums.powershell.org/t/trouble-with-invoke-webrequest/463>\
**Category:** PowerShell Help\
**Created:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/trouble-with-invoke-webrequest/463 "2011-12-31T18:30:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![archives](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@archives](https://forums.powershell.org/u/archives)\
**Post date:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/trouble-with-invoke-webrequest/463/1 "2011-12-31T18:30:00Z")

</div>

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.`

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:58pm UTC](https://forums.powershell.org/t/trouble-with-invoke-webrequest/463/2 "2024-05-16T20:58:09Z")

</div>


