Perl: recipe_8.1.pl PDF Print E-mail
Wednesday, 23 September 2009 20:57
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common qw(GET);

$UA = LWP::UserAgent->new();
$req = HTTP::Request->new( GET => "http://www.example.com/" );
$resp = $UA->request($req);

# check for error. Print page if it's OK
if ( ( $resp->code() >= 200 ) && ( $resp->code() < 400 ) ) {
print $resp->decoded_content;
} else {
print "Error: " . $resp->status_line . "\n";
}