Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Asynchronous HTTP requests

by Loops (Curate)
on Nov 23, 2014 at 06:01 UTC ( [id://1108140]=note: print w/replies, xml ) Need Help??


in reply to Asynchronous HTTP requests

It's in the header...

use AnyEvent::Loop; use AnyEvent::HTTP; http_get 'http://yahoo.com', sub { my ($body, $hdr) = @_; die $hdr->{U +RL} }; AnyEvent::Loop::run;

And if it wasn't, or there is other information you'd like to use.. capture it as a closure when the sub is defined.. for instance:

use AnyEvent::Loop; use AnyEvent::HTTP; use feature 'say'; for my $url ('yahoo.com', 'google.com') { http_get "http://$url", sub { say STDERR $url }; } AnyEvent::Loop::run;

Two separate callback subs are created, and in each of them $url will be set to the value it held when the http_get was run.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1108140]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-25 08:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found