Posted on 2005-12-22 19:28:18-08 by dablyputs
Authentication causes Useragent to exit after on request
I am using LWP::Parallel::UserAgent Version 2.57 on Redhat Linux AS3. My script gets a list of urls for mp3 files from a database then tries to fetch them using Parallel useragent. When I specify
$pua->redirect (1) and $pua->credentials( 'hostname:80', 'AuthRealm', 'username' => 'password' )
the useragent exits after one http response, regardless of the response code. If I specify $pua->redirect (0), exclude the credentials or include the http user in the url string, useragent will retrieve all of the urls in parallel. Is there a step I am missing when setting up the credentials or redirect? The full text of my script is below. Thanks, David
#!/usr/bin/perl -w require LWP::Parallel::UserAgent; use HTTP::Request; # display tons of debugging messages. See 'perldoc LWP::Debug' #use LWP::Debug qw(+); # shortcut for demo URLs my $url = "http://hostname"; my $reqs = [ HTTP::Request->new('GET', $url."/content/data1/39/738790/738790_full_128_mp3.mp3"), HTTP::Request->new('GET', $url."/content/data2/40/738791/738791_full_128_mp3.mp3"), ]; my $pua = LWP::Parallel::UserAgent->new(); $pua->in_order (1); # handle requests in order of registration $pua->duplicates(0); # ignore duplicates $pua->timeout (2); # in seconds $pua->redirect (1); # follow redirects $pua->credentials( 'hostname:80', 'AuthRealm', 'user' => 'password' ); foreach my $req (@$reqs) { print "Registering '".$req->url."'\n"; if ( my $res = $pua->register ($req) ) { print STDERR $res->error_as_HTML; } } my $entries = $pua->wait(); foreach (keys %$entries) { my $res = $entries->{$_}->response; print "Answer for '",$res->request->url, "' was \t", $res->code,": ", $res->message,"\n"; }
Direct Responses: 1508 | Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.