Thursday, April 23, 2015

perl: posting to multihomed hostname

What if you want to post to a hostname resolving to multiple IP addresses?
    local @LWP::Protocol::http::EXTRA_SOCK_OPTS = (
                                                   PeerAddr   => $my_hostname,
                                                   MultiHomed => 1,
                                                  );
    my $ua = LWP::UserAgent->new;
    my $response = $ua->post("https://$my_hostname/action",
                             Content_Type => 'application/x-www-form-urlencoded; charset=utf-8',
                             Content      => {
                                              param1 => 'value1',
                                              param2 => 'value2',
                                             });