自动登录Web表单 [英] Auto login web form

查看:168
本文介绍了自动登录Web表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下一个问题:

我有一个设备,它有一个xml页面(http://IP_device/counters.xml),我想要监控这个文件用于提取一些信息。问题来了,因为要访问此文件,我必须先登录表格(http://IP_device/frameCmd_Login.htm),如下所示:

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" />

为此我需要先登录表格(http:// IP_device)再下载xml文件。

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

我尝试过使用LWP,URL模块,但我不知道该怎么做。我是perl的新手。我试过的perl脚本是:

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?

推荐答案

authorization_basic 适用于标准HTTP身份验证,但Web表单是不同的。删除该方法调用并了解Web表单的功能。

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);

这篇关于自动登录Web表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆