Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Asynchronous HTTP requests

by Loops (Curate)
on Nov 23, 2014 at 06:01 UTC ( #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
Node Status?
node history
Node Type: note [id://1108140]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2021-04-20 00:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?