我試圖登錄到一個網站,使用這種形式與三個輸入進行身份驗證。爲什麼我可以用瀏覽器登錄這個表單,但不是LWP?
<form action="/login.html" method="post">
<div class="loginlabel1 aright">ID/Email: </div>
<div class="bsearchfield">
<input type="text" name="profid" class="inputBx" size="15" value="" />
</div>
<div class="clear"></div>
<div class="loginlabel1 aright">Password: </div>
<div class="bsearchfield">
<input type="password" name="password" class="inputBx" size="15" value="" />
</div>
<div class="clear"></div>
<div class="loginbutton1">
<input name="login"type="image" src="images/logi.gif" align="right" border="0" />
</div>
</form>
如果我通過瀏覽器登錄,登錄成功重定向我http://www.example.com/myhome.html。
但是,以下腳本不會將我登錄並返回相同的login.html
頁面。我錯過了什麼?我沒有收到任何錯誤消息。我發佈成功了嗎?
#!/usr/bin/perl -w
use LWP 5.64;
my $browser = LWP::UserAgent->new || die " Failed LWP USER AGENT : $!";
$ENV{HTTP_proxy} = "http://proxy:port";
$browser->env_proxy;
$browser->cookie_jar({});
my @Header = (
'User-Agent' => 'Mozilla/4.76 [en] (Win98; U)',
'Accept' => 'image/gif, image/x-xbitmap, image/jpeg,image/pjpeg, image/png, */*',
'Accept-Charset' => 'iso-8859-1,*,utf-8',
'Accept-Language' => 'en-US',
);
push @{$browser->requests_redirectable}, 'POST';
$response = $browser->post(
"http://www.example.com/login.html",
[
'profid' => 'username',
'password' => 'password'
],@Header
);
$response->is_success or die "Failed to post: ", $response->status_line;
print "Successfully posted username and password.\n" if $response->is_fresh;
#printf("%s",$response->content);
printf("%s\n", $response->status_line);
printf("%s", $response->header("Accept-Ranges"));
printf("%s", $response->header("Age"));
printf("%s", $response->header("ETag"));
printf("%s", $response->header("Location"));
printf("%s", $response->header("Proxy-Authenticate"));
printf("%s", $response->header("Retry-After"));
printf("%s", $response->header("Server"));
printf("%s", $response->header("Vary"));
printf("%s", $response->header("WWW-Authenticate"));
delete $ENV{HTTP_PROXY};
也許您可以嘗試診斷問題。你是否得到重定向響應代碼或200 OK或其他東西? – 2011-04-07 19:11:40
不,它將返回給我相同的登錄頁面。無錯誤代碼 – Jean 2011-04-07 19:18:25
你的迴應代碼是什麼? 200行嗎?什麼是完整的標題? – 2011-04-07 19:39:10