Hello,

I am trying to get WWW::Mechanize to run while at work. To get out to the internet from our web browser we use a proxy along with a username/password, ie. the first time I bring up my web browser to an external web address I enter my username and password and the proxy lets me out to external internet addresses.

In the past I would use LWP::UserAgent to get an external web page with the following script:

#!/usr/local/bin/perl use LWP::UserAgent; use URI; use Getopt::Long; GetOptions(qw(proxy)); $user = "myusername"; $passwd = "mypassword"; foreach $url2get (@ARGV) { $url = new URI "http://$url2get"; $ua = new LWP::UserAgent; $req = new HTTP::Request GET => $url; if($opt_proxy) { $ua->agent("Mozilla/4.05"); # pretend I am a Netscape browser $ua->proxy(['http'], 'http://wwwproxy.mycompany.com:1080'); $req->proxy_authorization_basic($user,$passwd); } $res = $ua->request($req); # check the outcome if ($res->is_success) { print $res->content; } else { print "Error: " . $res->code . " " . $res->message; } }

Although LWP::UserAgent says it can handle a proxy I couldn't figure out a way to get it to work with a proxy that expects a username and password and somehow found in a web search something similar to how the above scripts works.

Ok, now I am trying to use WWW::Mechanize and it says to handle a proxy it relies or leverages on LWP::UserAgent for this. I can replace LWP::UserAgent with WWW::Mechanize in the above script to fetch a web page fine but the other aspects of WWW::Mechanize such as "following" a link, "click", etc. will get denied by the proxy as they dont have the URI and HTTP::Request stuff happening to them.

Has anyone ever gotten LWP::UserAgent to work with a proxy with username/password without resorting to the use of URI and HTTP::Request like above as if I can do this I then think WWW::Mechanize would work similarly?

Thanks, perlhack


In reply to WWW::Mechanize and proxy with username/password by perlhack

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.