服务器实际上无法识别我在下面的代码中使用 WWW::Mechanize 设置的 cookie 的原因是什么?
#!/usr/bin/perl
use strict;
use warnings;
use HTTP::Cookies;
use WWW::Mechanize;
my $cookie_jar = HTTP::Cookies->new(
file => "$ENV{'HOME'}/lwp_cookies.dat",
autosave => 1,
ignore_discard => 1
);
my $mech = WWW::Mechanize->new(
agent => 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13',
cookie_jar => $cookie_jar
);
$mech->get("http://somesite.ru");
$cookie_jar->set_cookie(1, "__cookie", '1', "/", ".somesite.ru");
#the following line prints the cookie's data
print $cookie_jar->as_string, "\n";
$mech->post("http://somesite.ru/action.php",
['foo' => 'bar']);
如您所见,服务器运行 php。如果我放入那个 action.php 脚本:
var_dump($_COOKIE);
无论如何,我会得到一个空数组...谢谢您的所有建议。