Perl 中的远程 Web 表单发布
我对 Perl 比较陌生,我试图创建一个 Perl 脚本来以 Web 表单远程登录并返回成功或失败。但它不起作用或者我错过了一些东西,而且它给了我一条错误消息:这是我写的:
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Response;
use HTTP::Request::Common qw(POST);
$ua = LWP::UserAgent->new;
$ua->agent("Mozilla 8.0...");
$username = "username";
$password = "password";
my $req = (POST 'http://www.domain.com/login.php',
["Username" => "$username",
"Password" => "$password"]);
$request = $ua->request($req);
$content = $request->content;
if ($res->is_success) {
print ("success");
exit;
}
else {
print ("failure");
}
这个脚本根本没有运行,我得到的错误是:
Can't call method "is_success" on an undefined value at c:\remotelogin.pl line 24.
I'm relatively new to perl, I was trying to create a perl script to remote login in a web form and return either sucess or failure. but its not working or i'm missing something, plus it give me an error message: Here is what i wrote:
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Response;
use HTTP::Request::Common qw(POST);
$ua = LWP::UserAgent->new;
$ua->agent("Mozilla 8.0...");
$username = "username";
$password = "password";
my $req = (POST 'http://www.domain.com/login.php',
["Username" => "$username",
"Password" => "$password"]);
$request = $ua->request($req);
$content = $request->content;
if ($res->is_success) {
print ("success");
exit;
}
else {
print ("failure");
}
this script is not running at all and the error i'm getting is:
Can't call method "is_success" on an undefined value at c:\remotelogin.pl line 24.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它的重要性怎么强调都不为过,
尤其是在学习 Perl 时。在本例中,您有一个未声明的变量
$res
。也许是由于拼写错误?如果你使用了严格和警告,你会得到一个编译错误:严格和警告可能会产生很多令人生畏的错误,但是一旦你学会了如何避免它们,你就会意识到它们节省了你的时间和精力,而不是相反。
It can't be stressed enough how important it is to
Especially when learning perl. In this case, you have an undeclared variable
$res
. Due to a typo perhaps? If you have used strict and warnings, you would have gotten a compilation error:Strict and warnings may give a lot of intimidating errors, but once you learn how to avoid them, you realize they save you time and effort rather than the opposite.
$res
应替换为$request
。并且
使用严格;使用警告;
$res
should be replaced with$request
.And
use strict; use warnings;