在 Perl 中使用 Cookie

发布于 2024-11-19 09:20:06 字数 693 浏览 3 评论 0原文

我想在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一曲爱恨情仇 2024-11-26 09:20:06

cookies.txt 的内容应该是由 HTTP::Cookies 生成的文件,描述 cookie 名称、值、域和过期时间。您提供给它的文件不是它使用的格式,因此不会加载它。

The content of cookies.txt is supposed to be a file generated by HTTP::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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文