简体   繁体   中英

Perl WWW::Mechanize: How can I specify the destination IP address independently of the URL?

I want to use Perl www::mechanize to connect to the webserver and request a resource. Eg http://www.my.domain/test.html . But I want to specify the IP address independently from the hostname in the URL.

For example: www.my.domain resolves to 1.1.1.1, but I want to connect to 2.2.2.2.

I want to do this to test multiple web servers behind a load balancer.

use LWP::UserAgent::DNS::Hosts ;

It works fine with WWW::Mechanize.

use LWP::UserAgent::DNS::Hosts;
use WWW::Mechanize;

LWP::UserAgent::DNS::Hosts->register_host('www.my.domain' => '2.2.2.2');
LWP::UserAgent::DNS::Hosts->enable_override;

my $mech = WWW::Mechanize->new;
$mech->get('http://www.my.domain/test.html'); # connects to 2.2.2.2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM