On Fri, 2 Apr 2004 10:53:46 -0800 , Bajaria, Praful wrote:
> my $ua = LWP::UserAgent->new;
> $url = "http://www.cnn.com";;
> $response = $ua->get($url);
> if ($response->is_success) {
>       print "web site is working\n";
> } else { 
>       print "web site is not working\n";
> }
> quesion:
> 1) if the site is not woring, I would like to know why ?. How can I retrieve
> the error code?
> 2) what is the fail value ? i.e. $response->not_working.. etc.
Hello Bajaria,

        if the web site request ($ua->get()) fails $response->is_success will be 
false. By false I mean it isn't set to 1 which equals true. In your above example you 
would end up in the 'else'-block.

        To find out which error occured you need to take a look at $response->code. 
The number found in $response->code is in the range from 100 to 599. You can find more 
about these return codes by visiting 
<http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html>.

        To get a short human readable message about the meaning of $response->code 
take a look at $response->message.

        You can find out much more by entering the following line at the command 
prompt (or the terminal):

        perldoc LWP::UserAgent
        perldoc HTTP::Response

thanks
/oliver/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to