[英]Using a proxy with WWW::Mechanize
我試圖使用多個代理在我的服務器上載功能上執行測試。 到我通過api.ipify.org獲得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");
您僅為http設置了代理,但發出了https請求。 您還需要像這樣設置https的代理:
$m->proxy('https', ... put your https proxy here ...);
或對多個協議使用同一代理:
$m->proxy(['http','https'], ... );
另外,請確保至少使用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.