Reputation: 837
I'm trying to test the availability of web pages that are behind a load balancer. So I would like to write a powershell script to load a page from each web server individually. The problem is that the server uses host headers, so I can't manually specify the ip address, and I can't use just the url because it might get load balanced to a different server. Ideally, I'm looking for something like this.
$wc = New-Object net.webclient
$wc.downloadString("10.0.0.1", "http://test.com/home.html")
But I can't figure out how to do it. I'd perfer powershell, but if there is another windows utility that can do the job, I would be open to the idea.
Upvotes: 1
Views: 2991
Reputation: 131
I know this is an old question, but I recently needed to accomplish this myself and stumbled across this looking for a solution. I didn't find an answer elsewhere, but was able to discover it for myself and wanted to share in case anyone needs to do the same.
What you'll need to do is add a Headers value specifying your host before making the call by IP:
$wc = New-Object net.webclient
$wc.Headers.Add("Host", "test.com")
$wc.DownloadString("http://10.0.0.1/home.html")
This tells the WebClient call which server to send the page request to while still ensuring the request resolves successfully because it has the host header information as well.
*Keep in mind, if you're tweaking this to your own needs, each time you make a WebClient call, the Headers value will be reset. So be sure to execute $wc.Headers.Add() and $wc.DownloadString() together.
Upvotes: 3