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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |