当我执行代码时,它会给出302 Moved Temporarily Error 如果您在此代码中发现任何错误,请告诉我们。
#!C:\Perl64\bin\perl
print "Content-type: text/html\n\n";
# seraph.pl - search for Codex Seraphinianus on abebooks
use strict;
my $out_file = "result_seraph.html"; # where to save it
use LWP;
my $browser = LWP::UserAgent->new;
my $response = $browser->post('http://dogbert.abebooks.com/abe/BookSearch',
# That's the URL that the real form submits to.
[
"ph" => "2",
"an" => "",
"tn" => "Codex Seraphinianus",
"pn" => "",
"sn" => "",
"gpnm" => "All Book Stores",
"cty" => "All Countries",
"bi" => "Any Binding",
"prl" => "",
"prh" => "",
"sortby" => "0",
"ds" => "100",
"bu" => "Start Search",
]
);
die "Error: ", $response->status_line, "\n"
unless $response->is_success;
open( OUT, ">$out_file" ) || die "Can't write-open $out_file: $!";
binmode(OUT);
print OUT $response->content;
close(OUT);
print "Bytes saved: ", -s $out_file, " in $out_file\n";
我可以申请哪些更正请告诉我
答案 0 :(得分:3)
来自the manual:
$ ua-> requests_redirectable(\ @requests)
这将读取或设置
$ua->redirect_ok(...)
允许重定向的对象的请求名称列表。默认情况下,这是['GET', 'HEAD']
,根据RFC 2616.要更改为包含' POST', 考虑:push @{ $ua->requests_redirectable }, 'POST';
答案 1 :(得分:1)
你使用的是与Perl& amp;相同的代码。 LWP书:http://lwp.interglacial.com/ch05_06.htm
这是非常古老的,同时它引用的URL已经移动,这正是错误消息所说的。
要解决此问题,您必须允许重定向,请使用以下代码
my $browser = LWP::UserAgent->new;
push @{$browser->requests_redirectable}, 'POST';