Bjoern has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; use diagnostics; use LWP::UserAgent; use HTTP::Request; use HTTP::Response; use IO::Handle; my $Proxy_Username='admin'; my $Proxy_Password='adminpw'; my @Proxies = ( "http://proxy1:23651/proxy-proxy1-proxy/bin/sitemon?doit HTTP/ +1.0", "http://proxy2:23651/proxy-proxy2-proxy/bin/sitemon?doit HTTP/ +1.0", "http://proxy3:23651/proxy-proxy3-proxy/bin/sitemon?doit HTTP/ +1.0", "http://proxy4:23651/proxy-proxy4-proxy/bin/sitemon?doit HTTP/ +1.0"); STDERR->autoflush(1); STDOUT->autoflush(1); while (1==1) { my $ReadableTime=localtime(time()); print $ReadableTime," --> "; foreach (@Proxies) { my $URL=$_; my $UA = LWP::UserAgent->new(); # create new user agent $UA->agent("Mozilla/4.7 [en] (WinNT; I)"); # needs to be set like +this to get an answer from the proxy server $UA->timeout(15); # give the user agent some input $UA->max_size(5000); # more input my $Request = HTTP::Request->new(GET => $URL); # create new reques +t $Request->referer("http://wizard.yellowbrick.oz"); # perplex the l +og analysers (stolen code) $Request->authorization_basic($Proxy_Username,$Proxy_Password); # +some more input for the request my $Response = $UA->request($Request); # off goes the request if ($Response->is_error()) { # ups, some error here print "something wrong happened contacting $URL....\n"; } else { # everything went ok my $OffWeGo=0; my $Content = $Response->content(); my @ContentArray; # original array my @NewContentArray; # text between two boundaries @ContentArray=split(/\n/,$Content); # bring on the lines foreach (@ContentArray) { if (($_=~/--THIS_STRING_NEVER_HAPPENS/) && ($OffWeGo==0)) +{ $OffWeGo=1; next; } if (($_=~/--THIS_STRING_NEVER_HAPPENS/) && ($OffWeGo==1)) +{ $OffWeGo=0; last;} if ($OffWeGo==1) { push (@NewContentArray,$_); } } if ($NewContentArray[14]=~/(>\s)(\d*)(\s<)/) {print $2," "; } +# get number of active processes } } print "\n"; sleep (60); }
Edit kudra, 2002-09-11 Added a READMORE before the code
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Question concerning HTTP::Request and LWP::UserAgent
by BrowserUk (Patriarch) on Sep 12, 2002 at 04:22 UTC |