Re: Need help on LWP::UserAgent module!

Bill Moseley (moseley@hank.org)
Tue, 14 Nov 2000 05:42:39 -0800


At 05:06 PM 11/14/00 +0800, spring wrote:
>My program works fine when test on most URL, but with some, I always get a
>error status such as 500, 403,etc, even when the url can be visited
>correctlly in browser.

[snip]

>my $req = HTTP::Request->new(HEAD => $url);

Many servers are busted and will return a 500 error on a HEAD request.  I
remember Cold Fusion being one.

Maybe there's a better way, but this is what I do to validate a URL:

    $req = HTTP::Request->new( GET => $url );
    $ua->timeout( $LWP_GET_WAIT || 30 );
    $res = $ua->simple_request( $req, sub { die }, 100 );

If I remember correctly, there are cases where the timeout() setting didn't
work and the request would still hang (slow DNS?).  So you can wrap in an
eval block and use an alarm, if needed.

When I have a question like this I tend to use telnet to debug -- using a
browser is usually not that helpful when debugging.




Bill Moseley
mailto:moseley@hank.org