我正在使用插件WWW::Scripter(WWW::Mechanize的子类)对我的主机登录页面进行身份验证。他们在登录页面上使用Ruby
了一些JavaScript
功能,所以我不能只使用该LWP::Agent
模块。这是代码:
#!/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";
我有以下错误:
Uncaught exception from user code:
error3
我花了几个小时在谷歌上搜索,我觉得我现在真的需要你的帮助。我将不胜感激任何有助于理解为什么我无法进行身份验证的帮助。如果重要的话,我的 Perl 版本在 Ubuntu 11 上是 5.10.1。
谢谢。
更新
我已将代码中的一行更改为:
$w->credentials($username, $password) or die "error3: $!\n";
现在只得到白页。如果我启用诊断编译指示,则会出现一个相当普遍的错误:
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.