문제

I am using Perl's WWW::Mechanize to send HTTP traffic to a site. It returns 503 Service Unavailable error as a result of the HTTP request sent to the site.

The problem is that the script dies after receiving this error. I do not want that to happen and instead the script should continue the execution. I want it to ignore that error.

$mech=WWW::Mechanize->new();
$mech->agent_alias('Windows IE 6');

$mech->get($url);

// code after this does not execute

print $mech->content();

How can I configure WWW::Mechanize to ignore the HTTP response code 503 and continue the execution?

Thanks.

도움이 되었습니까?

해결책

my $mech = WWW::Mechanize->new( onerror => undef );

$mech->get($url);
if (!$mech->success()) {
    die("$url: ".$mech->res->status_line());
}

print $mech->content();

Replace the die with whatever action you want to have take instead.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top