Resolved:
First of all, thanks everyone for your help.
1.Client used up all traffic on rented proxies, without warning me about it, so LWP::UserAgent was not able to use rented parent-proxies.
2. In http://proxy... link, last slash was missing, I tried to add it\delete it but it was useless due to a "traffic issue", when this issue was resolved, I added the slash again and... voila, it works! In other words:
my $cur_proxy = "http://$valid_routes[$j]"; # <--- Not working;
my $cur_proxy = "http://$valid_routes[$j]/"; #<--- Works as a charm
May be it's not supposed to be an issue, but for me it works somehow only with closing slash, atleast when I tried it.
I have some remote proxies for my needs, and I'm trying to use them simultaneously. Script should to change proxy used for serving requests before each new request. Proxy IP's are stored in array and then should be chosen randomly. I tried this appoach for UserAgent rotation and it worked, but it's not working for for proxy rotation. I hope some one can help me with this, thanks in advance.
my (@agents, @raw_routes, @valid_routes);
open( AGENTS, "<", "/etc/squid/ua.cfg" );
while( <AGENTS> ) {
s/#.*//;
next if /^(\s)*$/;
chomp;
push @agents, $_;
}
close(AGENTS);
open( ROUTES, "<", "/etc/squid/repeater/lib/routes.cfg" );
while( <ROUTES> ) {
s/#.*//;
next if /^(\s)*$/;
chomp;
push @raw_routes, "$_,ENABLED";
}
close(ROUTES);
my $ua = LWP::UserAgent->new();
sub cb {
my($request, $ua, $h) = @_;
$#valid_routes = -1;
my $i = $#agents + 1;
$i = rand($i);
$i = int $i;
foreach my $item (@raw_routes) {
$item =~ s/,ENABLED//;
push @valid_routes, $item unless $item =~ m/DISABLED/;
}
my $j = $#valid_routes + 1;
$j = rand($j);
$j = int $j;
my $cur_agent = $agents[$i];
my $cur_proxy = "http://$valid_routes[$j]";
$request->proxy_authorization_basic( 'uname', 'passwd');
$ua->proxy(['http'], $cur_proxy);
$request->header('User-Agent' => $cur_agent);
$ua->timeout(120);
}
$ua->add_handler( request_preprepare => \&cb, { m_method => 'GET' } );