in reply to Re: Login, post, reload.
in thread Login, post, reload.

Thank you chromatic! The code in question works perfectly when the $perlmonks variable is changed to "www.perlmonks.org". I guess the upside to this debacle is learning a few different techniques for posting to cookie-login sites, and understanding why many cookies are set in the form: .domain.net

Joy!

Update: Here's the sub using merlyn's instructions for the cookie_jar. When using this code for perlmonks note the odd node_id=>'16046' parameter in the requests. This is done to ensure a small response. In this example it's an xml node. If omitted the monastery gates is returned making the operation much heavier than it needs to be.
sub sendit{ my$message = shift; my$ua = LWP::UserAgent->new; $ua->cookie_jar(HTTP::Cookies->new); my$req = POST ($pmurl, [ op=>'login',user=>$username,passwd=>$password,node_id=>'16046']); my$res = $ua->request($req); $req = POST ($pmurl, [ op=>'message',message=>$message,node_id=>'16046']); $res = $ua->request($req); print header; &talk(); }

Update2: After experimenting i found that the saved cookie file will be empty when merely using:

$ua->cookie_jar(HTTP::Cookies->new(file => ".cookies", autosave => 1)) +;
unless the cookie_jar is told to save cookies without an expiration date by adding the ignore_discard parameter:
$ua->cookie_jar(HTTP::Cookies->new(file => ".cookies", autosave => 1, +ignore_discard => 1));
or, better yet, by not using ignore_discard, but instead adding an 'expires' parameter to the login request:
my$req = POST ($pmurl, [ op=>'login',user=>$username,passwd=>$password,expires=>'+10y',node_id= +>'16046']);
Thanks merlyn.