Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: LWP::Simple - so they say!

by bart (Canon)
on Apr 20, 2012 at 11:26 UTC ( #966178=note: print w/replies, xml ) Need Help??


in reply to LWP::Simple - so they say!

Perhaps your webserver just doesn't respond to "HEAD" requests. Shit happens.

In that case, I'd call plain "GET" but you could abort halfway. You then will have to use a callback. See getprint (in LWP::Simple) as an example, which I have reproduced here:

sub getprint ($) { my($url) = @_; my $request = HTTP::Request->new(GET => $url); local($\) = ""; # ensure standard $OUTPUT_RECORD_SEPARATOR my $callback = sub { print $_[0] }; if ($^O eq "MacOS") { $callback = sub { $_[0] =~ s/\015?\012/\n/g; print $_[0] } } my $response = $ua->request($request, $callback); unless ($response->is_success) { print STDERR $response->status_line, " <URL:$url>\n"; } $response->code; }
You'd have to reproduce this but of course with a different callback... With die and eval BLOCK, it might just work.

Replies are listed 'Best First'.
Re^2: LWP::Simple - so they say!
by Anonymous Monk on Apr 20, 2012 at 11:52 UTC

    No need to abort with max_size

    #!/usr/bin/perl -- use strict; use warnings; use WWW::Mechanize; my $url = 'http://example.com'; my $ua = WWW::Mechanize->new( qw/ max_size 1 autocheck 1 show_progress 1 / ); eval { $ua->head($url); 1 } or $ua->get($url); print $ua->dump_headers; __END__

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://966178]
help
Chatterbox?
[1nickt]: You must twist and pull! If you burn, use tea tree oil etc, the tick barfs (inside your blood vessel) and you get all the loevely bacteria in his gut transferred to yours.
[1nickt]: tweesers work just fine
[hippo]: Hope everyone else is enjoying their lunch too.
[1nickt]: However, note that it takes between 2 and 4 hours for a tick to be able to start transmitting bacteria. So even if it has burrowed in and started eating, if you get it soon you should be OK.
[perldigious]: 1nickt: No more red meat! It would be more humane to just kill you, wouldn't it! :-)
[1nickt]: Just don't make it barf.
[1nickt]: perldigious that's exactly what my stepson says.
[1nickt]: the tick that can make you a vegetarian
[perldigious]: Your Mother: Yeah, I have a tool for ticks that I use (mostly on my dogs thankfully), but it's just a cheapo one I got from my vets office... it works pretty good though.
erix saw a tick in a natural history museum collected from the scrotum of the curator (it was removed)

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2017-05-24 13:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?