468,505 Members | 1,545 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

Problem with detecting error by LWP::UserAgent

Hello
I have a website on 2 servers. I want to make a script which checks is first
server availbale (he often breaks down) and redirects to 1st or 2nd server.
Script works well if an error is the 404 error, but it doesn't work if
server doesn't answer (and that's what I want). Can anyone help me? This is
the code:

#!/usr/bin/perl
##
##
##

use LWP::UserAgent;
use CGI;
$| = 1;
my $query = new CGI;
$ua = LWP::UserAgent->new;
$ua->agent("MyApp/0.1 ");

my $req = HTTP::Request->new(GET => 'http://pierwszy.serwer/index.php');
$req->content_type('application/x-www-form-urlencoded');

my $res = $ua->request($req);

if ($res->is_success) {
print $query->redirect("http://first.server/index.php");
} else {
print $query->redirect("http://second.server/index.php");
}

Jul 19 '05 #1
0 2755

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Woogie | last post: by
reply views Thread by Chandra | last post: by
2 posts views Thread by haimk63 | last post: by
reply views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.