WWW :: Mechanize ssl跨站点登录失败cookie_jar没有填充

时间:2015-02-12 18:17:02

标签: perl authentication ssl mechanize www-mechanize

网址$ url,重定向到https://auth.outside.com/secure/login以通过SSL进行身份验证。一旦您登陆页面,该站点就会存储一些cookie,还会在成功进行身份验证时存储一些cookie。但是,即使我设法登陆页面,我也没有填充cookie文件。这是谷歌的一个例子,但真正的URL是不同的。

CODE

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


my $userAgent = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0';
my $cookie_file = 'auth_cookies.txt';
$ENV{HTTPS_PROXY} = 'http://myproxy.net:8080';

my $google='https://www.google.com';

my $url = $google;
my $tempfile='download_details';

my $mech = WWW::Mechanize->new(
    noproxy => 0,
    agent => $userAgent,
    cookie_jar => HTTP::Cookies->new( file => $cookie_file )
    );

my $result=$mech->get( $url, ':content_file' => $tempfile );
print sprintf( "User-Agent %s\n  redirects to: %s\n\n", $userAgent, $mech->uri() );
print "result=$result\n";

输出如下:

User-Agent Mozilla / 5.0(X11; Ubuntu; Linux x86_64; rv:35.0)Gecko / 20100101 Firefox / 35.0   重定向到:https://www.google.com

导致= HTTP ::响应= HASH(0x3474ef0)

不会创建任何Cookie文件,即使您在firebug中看到一堆Cookie。

1 个答案:

答案 0 :(得分:1)

添加此代码后,文件正在填充......

$mech->cookie_jar->set_cookie(
    qw(
        3
        cat
        buster
        /
        .example.com
        0
        0
        0
    )
);