2015-05-11 73 views
0

一起使用代理我試圖在我的服務器上執行測試使用多個代理服務器上傳功能。當我通過api.ipify.org得到我的IP時。控制檯輸出我的真實IP,而不是代理IP。與WWW :: Mechanize

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; 
    }} 

回答

2
$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的版本至少爲6.06: :UserAgent和LWP :: Protocol :: https爲代理與https的正確支持,即

use LWP::UserAgent; 
print LWP::UserAgent->VERSION,"\n"; 

use LWP::Protocol::https; 
print LWP::Protocol::https->VERSION,"\n"; 
+0

我相當新的perl(昨天開始編程perl)。你能否解釋我可以如何爲https設置代理,並檢查模塊的版本? – Rarw

+0

@Rarw:見編輯的回覆 –

相關問題