Perl: recipe_8.2.pl PDF Print E-mail
Wednesday, 23 September 2009 21:01
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
$URL = "http://www.example.com/login.php";
$UA = LWP::UserAgent->new();

$req = HTTP::Request::Common::POST( "$URL",
Content_Type => 'form-data',
Content => [
USERNAME => 'admin',
PASSWORD => '12345',
Submit => 'Login'
]
);
$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";
}