use HTTP::Request::Common;
use LWP::UserAgent;
use XML::Parser;
use CGI;
use URI::Escape;my $ua = LWP::UserAgent->new;
my $uri = "http://myWebService.com?param1=" . $gVar1 . "¶m=" . $gVar2;my $req = HTTP::Request::Common::POST( $uri);
my $result = $ua->request( $req );
my $webServiceXML = $result->content;
Is there a way to set some sort of timeout around the call in case the web service is down? Currently if the server the web service is on is down the script just runs and runs eventually coming back with a blank screen. I want to add something like:
if(web service-Call-Time > 10 seconds) {
web service is down, insert exception code here
}
Any ideas?
use HTTP::Request::Common;
use LWP::UserAgent;
use XML::Parser;
use CGI;
use URI::Escape;
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
my $uri = "http://myWebService.com?param1=" . $gVar1 . "¶m=" . $gVar2;
my $req = HTTP::Request::Common::POST( $uri);
my $result;
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm(10);
$result = $ua->request($req);
alarm(0);
};
return 'web service is down' if $@ eq "alarm\n";
my $webServiceXML = $result->content;