[英]Using a proxy with WWW::Mechanize
Im trying to perform tests on my servers upload function using several proxies. 我试图使用多个代理在我的服务器上载功能上执行测试。 By the time I get my ip through api.ipify.org. 到我通过api.ipify.org获得IP的时候。 The console outputs my true ip, not the proxies ip. 控制台输出我的真实IP,而不是代理IP。
use strict; use warnings;
use WWW::Mechanize;
my $file = "proxies.txt";
open (FH, "< $file") or die "Can't open $file for read: $!";
my @lines = <FH>;
close FH or die "Cannot close $file: $!";
print "Loaded proxy list";
my $m = WWW::Mechanize->new(
autocheck => 1,
agent_alias => 'Mozilla',
cookie_jar => {},
ssl_opts => {verify_hostname => 0},
quiet => 0,
);
my $httpl = "http://";
$m->no_proxy('localhost');
my $ua = LWP::UserAgent->new;
for(my $i=0; $i < 47; $i++)
{
$m->proxy('http', $httpl . '' . $lines[$i]);
print "Connecting to proxy " . $lines[$i];
$m->get("https://api.ipify.org?format=json");
print $m->content;
for(my $j = 0; $j <= 10; $j++){
$m->get("http://example.com");
system("node genran.js");
$m->post('http://example.com/upload.php',
Content_Type => "form-data",
Content => [
'password' => '',
'public' => 'yes',
'uploadContent' => [ 'spam.txt', 'Love pecons', 'Content_$
file => [ 'x86.png', 'image_name', 'Content-Type' => 'ima$
]
);
print $m->content;
}}
$m->proxy('http', $httpl . '' . $lines[$i]);
print "Connecting to proxy " . $lines[$i];
$m->get("https://api.ipify.org?format=json");
You set only a proxy for http but make a https request. 您仅为http设置了代理,但发出了https请求。 You need to set the proxy for https too like this: 您还需要像这样设置https的代理:
$m->proxy('https', ... put your https proxy here ...);
Or to use the same proxy for multiple protocols: 或对多个协议使用同一代理:
$m->proxy(['http','https'], ... );
Also, make sure that you use at least version 6.06 of LWP::UserAgent and LWP::Protocol::https for proper support of proxies with https, ie 另外,请确保至少使用LWP :: UserAgent和LWP :: Protocol :: https 6.06版本,以正确支持使用https的代理,即
use LWP::UserAgent;
print LWP::UserAgent->VERSION,"\n";
use LWP::Protocol::https;
print LWP::Protocol::https->VERSION,"\n";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.