CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
WWW::Mechanize $mech->get($URI) locks for 1 min

 



jiteshar965
New User

Feb 20, 2017, 12:16 PM

Post #1 of 1 (810 views)
WWW::Mechanize $mech->get($URI) locks for 1 min Can't Post

Hi,
I am trying to login to an https URL and then subsequently making additional API call using the same instance of WWW::Mechanize as the login returns a session. I observed that script works perfectly fine except it gets lock exactly for 60 seconds at each time when it makes request to sever. First time it calls $mech->get($URI), it gets stuck for 60 seconds. After that it fills the user/pwd, and it makes $mech->submit(), again it gets stuck for 60 seconds. And finally it makes API call using the same session by calling $mech->get($URI), it again gets stuck for 60 seconds. If I use curl utility for login and then making api call, the total time is just in couple of seconds. Any help/suggestion will be highly appreciated. Thanks.

Here is my perl script:

Code
use HTTP::Cookies; 
use Data::Dumper;
use JSON;
use WWW::Mechanize;
my $user = "<username>";
my $passwd = "<password name>";
my $URL = 'https://<IP>';
my $URI = $URL;
my $mech = WWW::Mechanize->new(keep_alive => 50,
autocheck => 1,
agent => 'wonderbot 1.01',
noproxy => 0,
onwarn => undef,
stack_depth => 20,
quiet => 1
);
$mech->agent('User-Agent=Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5');
$mech->ssl_opts(verify_hostname => 0);
print "System Time Prior to login " . time ."\n";
$mech->get($URI);
print "System Time After login " . time ."\n";
if(!$mech->success){
print "Status: ".$mech->status."\n";
}
$mech->field('j_username',$user);
$mech->field('j_password',$passwd);
print "System Time after user/pwd setting " . time ."\n";
$mech->submit();
print "System Time After submit call " . time ."\n";
$out = $mech->content;
print Dumper($out);
$URI = $URL.'/dataservice/device';
print "System Time Prior to API call " . time ."\n";
$mech->get($URI);
print "System Time After API call " . time ."\n";
if(!$mech->success){
print "Status: ".$mech->status."\n";
}
print "System Time Prior to assigning output to out variable " . time ."\n";
$out = $mech->content;
print "System Time After assigning output to out variable " . time ."\n";
print Dumper($out);



(This post was edited by FishMonger on Feb 20, 2017, 1:31 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives