Question

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.

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top