Auto login web form

丶灬走出姿态 提交于 2019-12-12 03:20:39

问题


I have the next problem:

I have a device that it has an xml page (http://IP_device/counters.xml), I want to monitor this file for extract some information. The problem comes because for access to this file, previously I must login into a form (http://IP_device/frameCmd_Login.htm) like this:

<form method="get"  action="/Action_Login" onsubmit="return MD5HASH()">
<font color="#000000" align="center">Please Enter Password</font>
<input size="21" type="password" value="" name="LOGINPASSWORD" id="PD" />
<input name="submit" type="submit" value="LOGIN" />

For that I need to log in into the form before (http://IP_device) and then download the xml file.

I've tried with the LWP, URL modules but I don't know how to do this. I'm a newbie with perl. The perl script I've tried is:

#!/usr/bin/perl
use LWP::UserAgent;

my $ua = new LWP::UserAgent;
my $req = new HTTP::Request(GET => 'http://IP_device/frameCmd_Login.htm'); 
$req->authorization_basic("password123");

my $res = $ua->request($req);

if ($res->is_success) 
{
    my $file = $res->content;
    print $file;
} 
else 
{
    die $res->status_line;
}

Anyone knows how to achieve this issue? Anyone can help me?


回答1:


authorization_basic is good for standard HTTP authentication, but Web forms are something different. Remove that method call and learn how Web forms function.

Following is the simplest change to your code to make it work. Note we are targeting the resource in the form's action attribute directly.

my $u = URI->new('http://IP_device/Action_Login');
$u->query_form(LOGINPASSWORD => 'password123');
my $req = HTTP::Request->new(GET => $u->as_string);


来源:https://stackoverflow.com/questions/8670353/auto-login-web-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!