(no subject)

Otis Gospodnetic (otis@dominis.com)
Sat, 6 Mar 1999 01:05:12 -0500


>   Hello.  I posted the following message to a usenet group, but I
> thought maybe somebody on this mailing list could help as well.  Thanks
> in advance:
>
> ------------------------------------------------------------------
>
>   I have a list of url's and I need to check three things.  First,
> did I get a response back from the server.  Second, was the file
> found or not?  Third (and this is important), was the response that
> I got back binary or text data?
>
>    Right now, I'm doing it this way:
>
> #--
> for ($pic_count = 0; $pic_count < 100; $pic_count++)
> {
>   $pic_url = $pic_array[$pic_count];
>   $agent    = LWP::UserAgent->new();

take this line above OUT of the loop. You only need to do it once.

>   print "TESTING: $pic_url";
>   $request  = HTTP::Request->new('HEAD', $pic_url);
>   $response = $agent->request($request);
>
>   $result = $response->code;
>
>   if ($result != '200')
>   {
>     print " not found ($result).\n";
>   } else {
>     print " ", $result, "\n";
>   }
> }
> #---
>
>   There's a few problems with this, though.  First, it's really
> slow.  I think it's because it's downloading the whole file (I'm

it may be slow because you are constructing a new UserAgent object for every
request. Bad.
It is not downloading the whole file if you are using HEAD request (you are
above)

> requesting binary files) before it gives a response or not.  What
> I'd like to do is just download the first 64 bytes or so and check
> that data.  Secondly, can I assume that 200 is the "everything was
> cool" response?  Also, how would I go about setting the timeout time
> before it returns an error?

type: perldoc LWP::UserAgent

check out the timeout() method for setting the timeout
then check HTTP::Status (I think) for is_error(), is_success(), and
is_info() methods, those are probably better than using ... != 200 ...

Otis Gospodnetic
--
eZines Database - over 3,000 magazines, newspapers, journals, e-zines...
http://www.dominis.com/Zines/?es