Unfortunately, your code looks okay... I would check to make sure you're sending the correct request to the server. I would also check out the
LiveHTTPHeaders plugin for Firefox/Mozilla to verify that the server is responding to your particular request with a Set-Cookie header.
I'm including also some code that I just threw together (based on stuff at
LWP) to test this, which definately works - it would log you in to PerlMonks and maintain the cookies in that cookie_jar file - which reminds me, when playing with these automated web-browsing scripts, its sometimes wiser to include a user-agent that looks like a regular ol' browser, in case the server gets confused.
use HTTP::Cookies;
use LWP;
$cookie_jar = HTTP::Cookies->new (
file => "cookie_jar.lwp",
autosave => 1,
);
$ua= LWP::UserAgent->new;
$ua->cookie_jar( $cookie_jar );
$ua->agent("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6)
+Gecko/20050317 Firefox/1.0.2");
my $req = HTTP::Request->new(POST => 'http://www.perlmonks.com/');
$req->content_type('application/x-www-form-urlencoded');
$req->content('node_id=131&op=login&user=Adrade&passwd=pass-goes-here&
+expires=%2B10y&login=Login');
my $res = $ua->request($req);
print $cookie_jar->as_string;
Best of luck,
-Adam
--
By a scallop's forelocks!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.