我想编写一个脚本来登录 Web 应用程序,然后移动到应用程序的其他部分:
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
use Data::Dumper;
$ua = LWP::UserAgent->new(keep_alive=>1);
my $req = POST "http://example.com:5002/index.php",
[ user_name => 'username',
user_password => "password",
module => 'Users',
action => 'Authenticate',
return_module => 'Users',
return_action => 'Login',
];
my $res = $ua->request($req);
print Dumper(\$res);
if ( $res->is_success ) {
print $res->as_string;
}
当我尝试此代码时,我无法登录应用程序。返回的 HTTP 状态码是 302,已找到,但没有数据。
如果我使用所有必需的内容发布用户名/密码,那么它应该返回应用程序的主页并保持连接活动以移动应用程序的其他部分。