-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