http://qs321.pair.com?node_id=482727

mp has asked for the wisdom of the Perl Monks concerning the following question:

In order to implement a DNS-based failover scheme, I need a way to fetch a web page from a server whose IP address is not listed in an A-record for the domain name (the backup server).

I have tried a number of approaches using LWP, including Direct a LWP connection to a different host, but have not found any that work reliably.

Can anyone show how to do this?

I would think that I should be able to use the IP address in the URL (http://1.2.3.4/) and force a Host header in a LWP request somehow, but after looking at the LWP documentation and trying several different approach, I've not come up with anything that works. Any help will be greatly appreciated.

Replies are listed 'Best First'.
Re: LWP - test website at multiple IPs
by Bob9000 (Scribe) on Aug 10, 2005 at 19:52 UTC

    I would think that I should be able to use the IP address in the URL (http://1.2.3.4/) and force a Host header in a LWP request somehow, but after looking at the LWP documentation and trying several different approach, I've not come up with anything that works.

    That was my first thought as well, and it seems to work just fine for me:

    $ua = new LWP::UserAgent; print $ua->get("http://1.2.3.4/", Host => "www.domain.com")->content;

      Thank you. This works perfectly. The request is made to IP=1.2.3.4, and the host header www.domain.com is sent in the request.