Thread LWP::Simple Timeout festlegen? (1 answers)
Opened by Gast at 2008-08-13 02:49

GwenDragon
 2008-08-13 11:36
#113474 #113474
User since
2005-01-17
14757 Artikel
Admin1
[Homepage]
user image
Mit CPAN:LWP::UserAgent ist es möglich, ein timeout zu setzen.
Schau mal in die Dokumentation bei CONSTRUCTOR METHODS.

Bei der Konstruktion des Useragent-Objekts:
Code: (dl )
1
2
3
my $ua = LWP::UserAgent->new(  
agent => 'Spinne/0.9',
timeout=>5 );

oder:
Code: (dl )
1
2
 my $ua = LWP::UserAgent->new;
$ua->timeout(10);


Beispielcode:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use strict;
use warnings;
use LWP::UserAgent;
 
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
 
my $response = $ua->get('http://search.cpan.org/');
 
if ($response->is_success) {
     print $response->decoded_content;  # or whatever
}
else {
     die $response->status_line;
}

View full thread LWP::Simple Timeout festlegen?