【问题标题】:Perl WWW::Mechanize: How can I specify the destination IP address independently of the URL?Perl WWW::Mechanize:如何独立于 URL 指定目标 IP 地址?
【发布时间】:2021-05-03 13:54:30
【问题描述】:

我想使用 Perl www::mechanize 连接到网络服务器并请求资源。例如。 http://www.my.domain/test.html。但我想独立于 URL 中的主机名指定 IP 地址。

例如:www.my.domain 解析为 1.1.1.1,但我想连接到 2.2.2.2。

我想这样做以测试负载平衡器后面的多个 Web 服务器。

【问题讨论】:

    标签: perl www-mechanize


    【解决方案1】:

    使用LWP::UserAgent::DNS::Hosts

    它适用于 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
    
    

    【讨论】:

    • 我必须添加 LWP::UserAgent::DNS::Hosts->enable_override;让它发挥作用。
    • 你说得对,我错过了。将其添加到答案中。
    猜你喜欢
    • 2013-11-03
    • 2012-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-24
    • 2012-06-10
    • 2011-12-14
    相关资源
    最近更新 更多