perl - Using a proxy with WWW::Mechanize -


im trying perform tests on servers upload function using several proxies. time ip through api.ipify.org. console outputs true ip, not proxies ip.

use strict; use warnings;     use www::mechanize;     $file = "proxies.txt";     open (fh, "< $file") or die "can't open $file read: $!";     @lines = <fh>;     close fh or die "cannot close $file: $!";     print "loaded proxy list";     $m = www::mechanize->new(         autocheck => 1,         agent_alias => 'mozilla',         cookie_jar => {},         ssl_opts => {verify_hostname => 0},         quiet => 0,     );     $httpl = "http://";     $m->no_proxy('localhost');     $ua = lwp::useragent->new;     for(my $i=0; $i < 47; $i++)     {     $m->proxy('http', $httpl . '' . $lines[$i]);     print "connecting 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 proxy " . $lines[$i]; $m->get("https://api.ipify.org?format=json"); 

you set proxy http make https request. need set proxy https this:

$m->proxy('https', ... put https proxy here ...); 

or use same proxy multiple protocols:

$m->proxy(['http','https'], ... ); 

also, make sure use @ least version 6.06 of lwp::useragent , lwp::protocol::https proper support of proxies https, i.e.

use lwp::useragent; print lwp::useragent->version,"\n";  use lwp::protocol::https; print lwp::protocol::https->version,"\n"; 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -