开发者

Perl WWW::Mechanize JSESSION issue

I am having a problem getting/staying logged in with perl mechanize to a website

Looking at the headers, it appears that the JSESSIONID keeps changing. I am using a cookie jar, but I think it's getting overwritten somehow.

#!/usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize;
use HTTP::Cookies;
use Crypt::SSLeay;

use LWP::UserAgent;
use Crypt::SSLeay::CTX;
use Crypt::SSLeay::Conn;
use Crypt::SSLeay::X509;

use LWP::Simple qw(get);
use LWP::Debug;

my $cookie_jar = HTTP::Cookies->new(ignore_discard => 1);
my $agent = WWW::Mechanize->new(cookie_jar => $cookie_jar, noproxy=>0);
$agent->agent_alias('Linux Mozilla');

$ENV{HTTPS_CA_DIR} = 'cert/';

my $user = 'xxxx';
my $pass = 'xxxx';

my $url = '';

print "\n\n=========================================================\nGOING TO LOGIN PAGE:\n";
my $res = $agent->get($url);

for my $key ( $res->header_field_names() ) {
    print $key, " : ", $res->header( $key ), "\n";
}
print "cookie: ".$agent->cookie_jar->as_string();
$agent->form_name('loginForm');
$agent->set_fields(
    userId => $user,
    password => $pass
);    
$agent->submit();


print "\n\n=========================================================\nREDIRECT:\n";
my $res = $agent->submit();

for my $key ( $res->header_field_names() ) {
    print $key, " : ", $res->header( $key ), "\n";
}
print "cookie: ".$agent->cookie_jar->as_string();   


my $cUrl = '';
$cookie_jar->revert;

print "\n\n=========================================================\nGOING TO CAMPAIGN PAGE:\n";
my $res = $agent->get($cUrl);

for my $key ( $res->header_field_names() ) {
    print $key, " : ", $res->header( $key ), "\n";
}
print "cookie: ".开发者_如何学JAVA$agent->cookie_jar->as_string();


I am not sure why this worked, but I was able to resolve this by utilizing LWP::ConnCache

$agent->conn_cache(LWP::ConnCache->new());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜