require LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
my $response = $ua->get('http://toolsview/bcp_tool/');
if ($response->is_success) {
print $response->content; # or whatever
}
else {
die $response->status_line;
}
the output I get is;
Which is a web page that requests users to login (i.e. to insert a user ID and a password then click on the 'Login' button).BCP Administrator Console
It abstracts away a lot of parsing and HTTP stuff, so you can do this (from the docs):
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
$mech->get( $url );
$mech->follow_link( n => 3 );
$mech->follow_link( text_regex => qr/download this/i );
$mech->follow_link( url => 'http://host.com/index.html' );
$mech->submit_form(
form_number => 3,
fields => {
username => 'yourname',
password => 'dummy',
}
);
$mech->submit_form(
form_name => 'search',
fields => { query => 'pot of gold', },
button => 'Search Now'
);
Look at lwpcook-there are examples with basic authentication from the webserver, or where POST is being used and the authentication is being provided by the pages themselves. I suspect these may at least help you get started. Alternately, it is my understanding that WWW::Mechanize might also be useful, with a recent article appearing on http://www.perl.com/ regarding HTTP::Recorder to generate WWW::Mechanize scripts.
Hope that helps....
http://www.perl.com/pub/a/2004/06/04/recorder.html
As the article points out, you may have some difficulty if you are using SSL to access this page. In that circumstance, you'll have to go through the HTTP::Recorder control panel, not just through the proxy.
I've used this set-up several times, and it's fast, and easy.
for more info on how to do that check out %perldoc lwpcookbook and this article on perl.com by Sean M. Burke. I found it's very useful for people who are new to LWP. if you want to get detail on LWP and all the html processing, check his book "Perl & LWP".
lynx -trace http://foo.bar/The trace file is a bit cluttered with debug info concerning how Lynx parses and renders HTML, but it is still pretty easy to follow.
You can also use HTTP::Request::Common to perform the automatic login process.
use HTTP::Request::Common; use LWP::UserAgent; $ua = LWP::UserAgent->new; $ua->request(POST 'http://url/loginscript', [ username => 'yourusername', password => 'yourpassword' ]);
- Ralph.
perlmonks.org content © perlmonks.org and a,s5, Anonymous Monk, atcroft, Joost, mako132, Qiang, spartan
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03