my $ua = LWP::UserAgent->new(max_size => 300);
for my $url (@urls) {
my $response = $ua->get($url);
if ($response->is_success) { print $response->content; }
else { die $response->status_line; }
}
| [reply] [d/l] |
300 bytes sounds a little arbitrary? If your need is only to confirm that the url in question is valid and will return content, consider the LWP::Simple head() function.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
| [reply] [d/l] [select] |
If you want to do something that isn't simple, don't use LWP::Simple. Use its bigger brother LWP::UserAgent. When invoking get, set the :content_cb and :read_size_hint fields, and die from the handler you set with :content_db after receiving 300 bytes.
Alternatively, forget about LWP::*. HTTP is quite simple, after the TCP handshake, it's one message from the client to the server, followed by one message from the server to the client. So, just open a socket, write your request on the socket, read back the reply, close the socket after reading 300 bytes. | [reply] [d/l] |