[tpm] WWW::Mechanize and setting cookies
Madison Kelly
linux at alteeve.com
Fri Aug 1 03:51:46 PDT 2008
Zoffix Znet wrote:
> You are not setting the cookie "domain". This works just fine:
>
> #!/usr/bin/env perl
>
> use strict;
> use warnings;
> use WWW::Mechanize;
>
> my $mech = WWW::Mechanize->new;
>
> $mech->get('http://zoffix.com/new/cookies.pl');
> print "BEFORE:\n", $mech->content, "\n";
>
> $mech->cookie_jar->set_cookie( 0, 'foo', 'bar', '/', 'zoffix.com' );
>
> $mech->get('http://zoffix.com/new/cookies.pl');
> print "AFTER:\n", $mech->content, "\n";
>
>
> Prints:
> BEFORE:
> Cookies:
>
> AFTER:
> Cookies:
> foo => bar
>
>
> If you are interested in the source code of that cookies.pl script see:
> http://www.zoffix.com/new/cookies.pl?source
>
>
> Cheers
Bingo!
I thought the domain was an optional method of letting a cookie work
across sub-domains, so I left it off. Doh!
Thank you very kindly!
Madi
More information about the toronto-pm
mailing list