I need to change the proxy server in one Perl run (process). But LWP::UserAgent
is always remembering the first proxy value.
When I start my program with proxy x.x.x.2
, this address is always used as proxy.
What is wrong?
The simple program Example:
getHTTP('http://my.com/', "http://x.x.x.1:3128");
getHTTP('http://my.com/', "http://x.x.x.2:3128");
getHTTP('http://my.com/', "");
getHTTP('http://my.com/', "http://x.x.x.3:3128");
sub getHTTP {
my ($url, $proxy) = @_;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->proxy(http => $proxy);
my $req = HTTP::Request->new(GET => $url);
return $ua->request($req)->as_string;
}
Output from HTTP log:
x.x.x.1 - - [09/Feb/2015:15:28:06 +0100] "GET / HTTP/1.0" 200 3467
x.x.x.1 - - [09/Feb/2015:15:29:07 +0100] "GET / HTTP/1.0" 200 3467
y.y.y.y - - [09/Feb/2015:15:29:08 +0100] "GET / HTTP/1.0" 200 3467
x.x.x.1 - - [09/Feb/2015:15:29:09 +0100] "GET / HTTP/1.0" 200 3467
(y.y.y.y is my no proxy address)
OS: Debian GNU/Linux 7
NEW findings: When I run next perl or shell scripts. The same result as above.
proxy.sh:
curl -x "http://x.x.x.1:3128" http://my.com/
curl -x "http://x.x.x.2:3128" http://my.com/
curl -x "http://x.x.x.3:3128" http://my.com/
Result: always x.x.x.1 proxy
proxy.pl:
`curl -x "http://x.x.x.4:3128" http://my.com/`;
`curl -x "http://x.x.x.5:3128" http://my.com/`;
`curl -x "http://x.x.x.6:3128" http://my.com/`;
Result: always x.x.x.4 proxy
It looks like the proxy settings cannot change in one shell process.