我正在尝试使用 cookie,LWP::UserAgent
但它们没有保存在文本文件中。我究竟做错了什么?
use v5.16;
use strict;
use warnings;
use Data::Dumper;
use LWP::UserAgent;
use HTTP::Cookies;
use Net::SSL ();
my $cookie_jar = HTTP::Cookies->new(
file => 'lwp_cookies.txt',
autosave => 1,
);
my $ua = LWP::UserAgent->new(
ssl_opts => { verify_hostname => 0 },
cookie_jar => $cookie_jar,
);
my $auth_url = 'https://my.site.url/path/authenticate';
use HTTP::Request::Common qw(GET);
my $req = HTTP::Request->new(GET => $auth_url);
$req->authorization_basic('username', 'password');
$ua->request($req);
say Dumper( \$cookie_jar );
转储的数据如下所示:
$VAR1 = \bless( {
'autosave' => 1,
'COOKIES' => {
'my.site.url' => {
'/' => {
'BLAH_COOKIE_KEY' => [
0,
'very_long_string',
undef,
1,
undef,
undef,
1
]
}
}
},
'file' => 'lwp_cookies.txt'
}, 'HTTP::Cookies' );
而且lwp_cookies.txt
只有这个:
#LWP-Cookies-1.0
我在 Win with Strawberry Perl 上。