簡體   English   中英

具有“ LWP :: UserAgent”錯誤的Perl“ HTTP :: cookies”“:看起來不像Netscape cookie文件”

[英]Perl “HTTP::cookies”“ with ”LWP::UserAgent“ error: ”does not look like a Netscape cookies file"

我正在嘗試在Perl腳本中執行curl --cookie cookies.txt "https://foo.example.org/bar"的等效操作。 我有一個cookie文件,我相信它是Netscape格式(制表符分隔),可以與curl配合使用。 HTTP::cookies抱怨:

cookies.txt在/System/Library/Perl/Extras/5.10.0/HTTP/Cookies/netscape.pm第21行,第1行中看起來像不是Netscape cookie文件。

我的腳本只是測試的存根:

#!/usr/bin/perl -w

use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
use HTTP::Cookies::Netscape;
my $cookie_jar = HTTP::Cookies::Netscape->new
                  ( 'file' => 'cookies.txt', );  
my $url = 'http://www.google.com/';
my $response = $ua->get( $url );
print "Return: $response->status_line\n";

cookies.txt文件實際上以注釋開頭:

# This content may be pasted into a cookies.txt file and used by wget

但是我嘗試刪除評論,並得到相同的確切錯誤。 cookies.txt文件具有Unix樣式行的結尾。

精氨酸!

事實證明,雖然curl對文件滿意,但HTTP::Cookes::Netscape模塊希望第一行是

# Netscape HTTP Cookie File

我加了,現在看來很高興。

(我找到了模塊源代碼並搜索了錯誤消息。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM