-2
的login.html发送POST数据
<form method="POST" action="login.php">
<input type="text" name="username">
<input type="password" name="password">
<button class="_sdf3">Login</button>
</form>
login.pl
#!/usr/bin/perl
use LWP::UserAgent;
my $username = "admin";
my $password = "pass2321";
my $url = "http://127.0.0.1/login.html";
my $ou = new LWP::UserAgent;
my $req = $ou->post($url,{ username => $username , password => $password , });
my $code = $req->code;
if ("$code" eq "302"){
print "Username And Password OK";
}else{
print "Username And Password BAD";
}
当我运行login.pl
我会看到Username And Password BAD
但数据是正确的!
我想,而在login.html的
'print“code = $ code = \ n”;' – toolic
总是包含'use strict;在Perl脚本的顶部使用警告'all';'。 LWP :: UserAgent没有'code'方法,所以'$ ou-> code'没有意义。你的意思是'$ req-> code',它在你的[HTTP :: Response](https://metacpan.org/pod/HTTP::Response)对象上调用'code'方法。 – ThisSuitIsBlackNot
...但我猜这不是你实际使用的代码,因为你已经显示将死于错误“无法定位对象方法”代码“通过包”LWP :: UserAgent “'在到达'else'块之前。 – ThisSuitIsBlackNot