Dienstag, 14. Juni 2011

Simple Web benchmark with Perl or faking web login with Perl

Sometimes it is not necessary to start Apache's jmeter or selenium for benchmarking a web site.
But one difficulty remains: Authentification.

What else is needed by common frameworks?
- HTTPS
- Cookies
  • Package libwww-perl (perl-libwww-perl-5.805-1.1.1.noarch or perl-libwww-perl)
  • Package HTTP
For details have a look at CPAN

Perl helps out with a few lines. Furthermore this also one way for automating web login to gain a valid session. This valid Session (or rather the Cookie) will be stored in the variable "$browser".

#!/usr/bin/perl
use LWP;
use Data::Dumper;
use HTTP::Cookies;
use Time::HiRes qw( time );

my $browser = LWP::UserAgent->new;
my $cookie_jar = HTTP::Cookies->new();
$browser->cookie_jar($cookie_jar);

my $loggedinPage = $browser->post(
'https://cv-parser.de/',
['username'=>'user', 'password' => 'password' ]
);
my $start = time();
print 'Header: '. Dumper($loggedinPage->{'_headers'})."\n";
my $end = time();
printf("Login: %.2f\n", $end - $start);


The only difficult part, is to evaluate the form parameter which the original site uses.
At this point Firebug or Chrome development bar is your friend.

Keine Kommentare: