Problem with detecting error by LWP::UserAgent

Discussion in 'Perl' started by Playker, Feb 24, 2005.

  1. Playker

    Playker Guest

    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");
    }
     
    Playker, Feb 24, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chandra

    Problem with LWP::USERAGENT

    Chandra, Feb 25, 2004, in forum: Perl
    Replies:
    0
    Views:
    520
    Chandra
    Feb 25, 2004
  2. Gaurav

    Problem using LWP::UserAgent

    Gaurav, Oct 2, 2003, in forum: Perl Misc
    Replies:
    1
    Views:
    253
    Tad McClellan
    Oct 2, 2003
  3. unreal

    LWP::UserAgent & threads problem

    unreal, Apr 30, 2004, in forum: Perl Misc
    Replies:
    0
    Views:
    104
    unreal
    Apr 30, 2004
  4. RP
    Replies:
    6
    Views:
    380
    Matt Garrish
    Jun 5, 2004
  5. David Karr
    Replies:
    9
    Views:
    969
    David Karr
    Aug 25, 2011
Loading...

Share This Page