gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 16:20:55 25 4
gpt4 key购买 nike

我想编写一个脚本来登录到一个 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.

关于perl - 如何使用 Perl 的 LWP 登录 Web 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1028929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com