加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

如何使用Perl的LWP登录Web应用程序?

发布时间:2020-12-15 23:35:56 所属栏目:大数据 来源:网络整理
导读:我想编写一个脚本来登录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 = 'use
我想编写一个脚本来登录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,但没有数据.

如果我发布所有必需的用户名/密码,那么它应该返回应用程序的主页并保持连接实时移动应用程序的其他部分.

解决方法

您可以将 WWW::Mechanize用于此目的:

Mech supports performing a sequence of page fetches including following links and submitting forms. Each fetched page is parsed and its links and forms are extracted. A link or a form can be selected,form fields can be filled and the next page can be fetched. Mech also stores a history of the URLs you’ve visited,which can be queried and revisited.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读