perlhack has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: WWW::Mechanize and proxy with username/password
by Anonymous Monk on Jun 26, 2003 at 17:35 UTC | |
|
Re: WWW::Mechanize and proxy with username/password
by Thelonius (Priest) on Jun 26, 2003 at 19:28 UTC | |
by tilly (Archbishop) on Jun 26, 2003 at 19:55 UTC | |
by perlhack (Acolyte) on Jun 26, 2003 at 20:33 UTC | |
|
Re: WWW::Mechanize and proxy with username/password
by tcf22 (Priest) on Jun 26, 2003 at 18:12 UTC | |
by perlhack (Acolyte) on Jun 26, 2003 at 18:33 UTC | |
by Corion (Patriarch) on Jun 26, 2003 at 18:36 UTC | |
|
Re: WWW::Mechanize and proxy with username/password
by Thelonius (Priest) on Jun 26, 2003 at 21:08 UTC | |
|
Re: WWW::Mechanize and proxy with username/password
by petdance (Parson) on Jun 29, 2003 at 04:40 UTC |