0
我想通過PERL提交表單。我已經設法提交表單,但是我在表單提交後收到一個顯示「無效會話流」的HTML頁面。如果我從瀏覽器提交,新頁面包含另一個表單。無效的會話流程
我無法找到該消息可能出現的原因。如果我在服務器端沒有任何訪問權限,是否可以排除故障?或者它必須從服務器端進行檢查?
我的代碼:
my $url = "https://MY_URL";
my $Browser = new LWP::UserAgent();
$Browser->ssl_opts(verify_hostname => 0,SSL_verify_mode => 0x00);
my $page = $Browser->get($url);
my $content = HTML::TreeBuilder->new_from_content($page->decoded_content) or die $!;
my $match = $content->find_by_attribute('name' => 'token');
my $token = $match->attr('value');
chomp($token);
my %fileds = ("DATA" => "STD111","token" => $token);
my $Page = $Browser->request(POST $url,\%fileds);
if ($Page->is_success){
print $Page->status_line."\n";
print $Page->content."\n";
}else{
print $Page->status_line."\n";
print $Page->message;
}
下面是從Firefox瀏覽網頁源
初始頁:
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1">
<title>Website Title</title>
</head>
<body>
<form method="post" action="/">
<input type="hidden" name="token" value="5f75b4fb68ed">
<input name="stdname">
<input type="submit" value="Submit">
</form>
</body>
</html>
輸出我得到:
200 OK
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1">
<title>Website Title</title>
</head>
<body>
<form method="get" action="/">
ERROR: Invalid session flow<br>
<input type="submit" value="Relogin">
</form>
</body>
</html>
當通過任何瀏覽器提交的實際着陸頁:
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1">
<title>Website Title</title>
</head>
<body>
<form method="post" action="/">
<input type="hidden" name="token" value="5f75b4fb68ed">
<input type="password" name="stdpass">
<input type="submit" value="Submit">
</form>
</body>
</html>
對於處理表單,我建議使用['WWW :: Mechanize'](https://metacpan.org/pod/WWW::Mechanize)。 – Miller 2014-09-11 08:18:54