anatoliy_v
anatoliy_v

Reputation: 1800

Perl WWW::Mechanize and authenticated proxy

I have a proxy with IP, Port, Login and Password. Is it possible to use this proxy with Perl's WWW::Mechanize?

Thanks.

Upvotes: 2

Views: 1766

Answers (1)

DVK
DVK

Reputation: 129423

  1. I'm not sure if there's a native way but here's a workaround which is claimed to work:

    http://www.perlmonks.org/?node_id=269358

    It's based on setting $ENV{HTTP_PROXY} to "http://login:password@proxyserver" where both login and password must be URI-encoded.

  2. Also, WWW::Mechanize is a subclass of LWP::UserAgent, and as such, what works in LWP should work on Mechanize (example from LWP Cookbook, PROXIES section)

    use LWP::UserAgent;
    $ua = LWP::UserAgent->new;  
    $ua->proxy(['http', 'ftp'] => 'http://username:[email protected]');
    $req = HTTP::Request->new('GET',"http://www.perl.com");
    $res = $ua->request($req);  
    print $res->decoded_content if $res->is_success;
    

Upvotes: 6

Related Questions