Hammy has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I have a web site that returns a string - true or false. I want to call that page from within perl with posting to the page to see whether or not to proceed. Is there a way to do this. I know I could do this if the other side was a soap service, but this is not - is there any way for me to fake it? Thanks. - Mark

Replies are listed 'Best First'.
Re: Server to Server communication
by tachyon (Chancellor) on Sep 10, 2004 at 04:08 UTC
    use LWP::Simple; my $site = 'http://.....'; my $res = get($site); if ( ! $res ) { print "Did not get response"; } elsif ( $res =~ m/true/i ) { # blah } elsif ( $res =~ m/false/i ) { # blah } else { print "Unknown response $res"; }

    cheers

    tachyon

      Sorry for the late response - thank you very much, this is what I was looking for!
Re: Server to Server communication
by johnnywang (Priest) on Sep 10, 2004 at 07:19 UTC
    Since you said "post", you will need LWP::UserAgent
    use strict; use LWP::UserAgent; my $url = "http://your url"; my $ua = LWP::UserAgent->new; my $res = $ua->post($url); if($res->is_success()){ my $content = $res->content(); if($content =~ /true/){ print "looks good\n"; }elsif($content =~ /false/){ print "something is wrong\n"; }else{ print "how can that be?\n"; } }else{ print "Uh-oh, time to work!\n"; }
    (Not tested)