I am using plugin WWW::Scripter (subclass of WWW::Mechanize) to authenticate to my host's login page. They use Ruby
with some JavaScript
functions on the login page, so I can't just use the LWP::Agent
module. Here is the code:
#!/usr/bin/env perl
use strict;
use warnings;
use diagnostics;
use LWP::Debug qw(+);
use LWP::ConnCache;
use WWW::Scripter;
my $url = 'https://control.vp.net/login';
my $username = 'example@example.com';
my $password = 'example';
my $w = WWW::Scripter->new(keep_alive => 1) or die "error1: $!\n";
$w->conn_cache(LWP::ConnCache->new);
$w->use_plugin('JavaScript') or die "error2: $!\n";
$w->credentials($url, undef, $username, $password) or die "error3: $!\n";
$w->get($url) or die "error4: $!\n";
print $w->content() or die "error5: $!\n";
I am having the following error:
Uncaught exception from user code:
error3
I have spent number of hours googling and I feel that I really need some of your help now. I will appreciate any help which help to understand why I can't authenticate. My Perl version is 5.10.1 on Ubuntu 11 if it matters.
Thanks.
Update
I have changed one line in the code to:
$w->credentials($username, $password) or die "error3: $!\n";
and getting just white page now. If I enable the diagnostics pragma, a rather general error appears:
Use of uninitialized value in subroutine entry at blib/lib/Net/SSLeay.pm
(autosplit into blib/lib/auto/Net/SSLeay/randomize.al) line 2227 (#1)
(W uninitialized) An undefined value was used as if it were already
defined. It was interpreted as a "" or a 0, but maybe it was a mistake.
To suppress this warning assign a defined value to your variables.
credentials
is good for standard HTTP authentication, but Web forms are something different. Remove that method call and learn how Web forms function. The JavaScript has no influence on the Web form, Mechanize is enough.
use strictures;
my ($url, $username, $password)
= qw(https://control.vps.net/login example@example.com example);
my $w = WWW::Mechanize->new;
$w->get($url); # automatically raises exception on HTTP errors
$w->submit_form(with_fields => {
'session[email_address]' => $username,
'session[password]' => $password,
});
die 'login failed'
if $w->content =~ /your email and password combination were incorrect/;