-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 At 1:05 PM -0400 8/18/98, Shawn O'Donnell wrote: } Has anyone had luck using Netscape-style cookies from MacPerl? } } I'm trying to write script that will get up early and download parts of the } newspaper for me. } } I can retrieve the cookies from the MagicCookie file, but Cookies.pm is You're sure about this? } failing to find the match between the URL in my HTTP::Request object and } the domain name hash buried in the Cookies object. } } I can't make sense of all the levels of references to hashes to figure out } what's going on. Reference to hashes as elements in hashes that you have } to look at by dereferencing. Or something like that. } } And I can't figure out why Cookies.pm is checking some odd paths. } } Any clues? In the meanwhile, I'll go re-read the "Reference" section in } Advanced Perl. I found a possible problem. Netscape seems to be storing cookies with expiry's in seconds past the Unix zero of time. This causes all Max-age's to be negative, which means "delete the cookie". So nothing from the cookie file ever gets loaded into $cookie_jar. Try this: use HTTP::Cookies; my $cookie_jar = HTTP::Cookies::Netscape->new ( File=>"HD:System Folder:Preferences:Netscape f:MagicCookie"); print $cookie_jar->as_string; and see what you get (I get nothing). Now make the following fix to HTTP::Cookie (replaces sub load in HTTP::Cookies::Netscape): package HTTP::Cookies::Netscape; use vars qw(@ISA); @ISA=qw(HTTP::Cookies); require Time::Local if $^O eq "MacOS"; my $offset = ($^O eq "MacOS") ? Time::Local::timelocal(0,0,0,1,0,70) : 0; sub load { my($self, $file) = @_; $file ||= $self->{'file'} || return; local(*FILE, $_); my @cookies; open(FILE, $file) || return; my $magic = <FILE>; unless ($magic =~ /^\# Netscape HTTP Cookie File/) { warn "$file does not look like a netscape cookies file" if $^W; close(FILE); return; } my $now = time() - $offset; while (<FILE>) { next if /^\s*\#/; next if /^\s*$/; chomp; my($domain,$bool1,$path,$secure, $expires,$key,$val) = split(/\t/, $_); $secure = ($secure eq "TRUE"); $self->set_cookie(undef,$key,$val,$path,$domain,undef, 0,$secure,$expires-$now, 0); } close(FILE); 1; } Run the above script again, and you should see all your cookies. Run your script, and you should get what you want. I successfully contacted amazon.com with your script, with paths and URL's modified. I will put a fixed version of libwww-perl-5.36 on my ftp site this evening or tomorrow. There are some other fixes necessary to properly deal with this everywhere. (This fix just gets the cookies defined so you can use them, but don't try a $cookie_jar->save just yet.) } } --Shawn } } } - - - - - - - - - - - - - - - - - - - - - - [snip] - ----- Paul J. Schinder schinder@pobox.com -----BEGIN PGP SIGNATURE----- Version: PGP for Personal Privacy 5.0 Charset: noconv iQA/AwUBNdohvVZaVc52j0XhEQJ5IACfbam3fndOQhFYVOTwz4Uf3GQuW04An0AE zpPj9SpOySY3L41qCYx1npiq =y4Qc -----END PGP SIGNATURE----- ***** Want to unsubscribe from this list? ***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch