在 Perl 中使用 Cookie
我想在 Perl 中使用 Cookie,但我有一个问题。 这是我的代码:
use LWP::UserAgent;
use HTTP::Cookies;
$xpl = new LWP::UserAgent(agent => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 Firefox/1.5.0.5');
$req = HTTP::Request->new(GET => 'http://example.com') or die "\n\n Failed to Connect, Try again!\n";
my $cookie_jar = HTTP::Cookies->new(file => 'cookie.txt');
$xpl->cookie_jar($cookie_jar);
$res = $xpl->request($req);
print $xpl->request($req)->as_string;
cookie.txt 的内容是: 0fea8e55a89187d306d7db060b7b9ab7 。当我运行此代码时,我收到此警告: cookie.txt 在 F:/Perl/lib/HTTP/Cookies.pm 第 432 行第 1 行似乎不包含 cookies。
我该怎么办? 提前致谢 。
I want to use Cookie in Perl but i have a problem .
it's my code :
use LWP::UserAgent;
use HTTP::Cookies;
$xpl = new LWP::UserAgent(agent => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 Firefox/1.5.0.5');
$req = HTTP::Request->new(GET => 'http://example.com') or die "\n\n Failed to Connect, Try again!\n";
my $cookie_jar = HTTP::Cookies->new(file => 'cookie.txt');
$xpl->cookie_jar($cookie_jar);
$res = $xpl->request($req);
print $xpl->request($req)->as_string;
and the content of cookie.txt is : 0fea8e55a89187d306d7db060b7b9ab7 . and when i runing this code i get this warning : cookie.txt does not seem to contain cookies at F:/Perl/lib/HTTP/Cookies.pm line 432, line 1.
what am i going to do ?
Thanks in Advance .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
cookies.txt
的内容应该是由HTTP::Cookies
生成的文件,描述 cookie 名称、值、域和过期时间。您提供给它的文件不是它使用的格式,因此不会加载它。The content of
cookies.txt
is supposed to be a file generated byHTTP::Cookies
describing cookie names, values, domains, and expirations. The file you're giving it isn't in the format it uses, so it's not being loaded.