asiufy has asked for the wisdom of the Perl Monks concerning the following question:

I'm using HTTP::Cookies to capture the cookies sent back from an HTTP Post. I used the following LWP::UserAgent method call:
$ua->cookie_jar(HTTP::Cookies->new(file => "cookies.txt", autosave => +1));
And then, when the request method is called, the file is generated, but it is empty, with only the #LWP-Cookies-1.0 comment line... I have found a node here that says that HTTP::Cookies can't handle SetCookies3 header fields, so I checked the contents of the HTTP::Response object, and here's what I got:
Set-Cookie: JSESSIONID=6kt778cd11;Path=/smp Set-Cookie2: JSESSIONID=6kt778cd11;Version=1;Discard;Path="/smp"
So, it seems normal, no SetCookie3... Yet, I can't get the cookie contents ... What could be the problem? Thanks!

Replies are listed 'Best First'.
Re: HTTP::Cookies is saving an empty file
by chromatic (Archbishop) on Jan 23, 2002 at 02:17 UTC
    Does passing ignore_discard => 1 in the constructor help anything? How about calling $cookie_jar->save() explicitly?
      Congrats chromatic, you get a cookie :)
      It was the ignore_discard => 1...
      Still it seems funky that the cookie data is saved as a Set-Cookie3 field...
      Thanks, folks!
RTFM: HTTP::Cookies is saving an empty file
by larryk (Friar) on Jan 23, 2002 at 14:47 UTC
    You have to make the request and then call extract_cookies, hold on...

    From the HTTP::Cookies docs

    $cookie_jar->extract_cookies($response); The extract_cookies() method will look for Set-Cookie: and Set-Cookie2: headers in the *HTTP::Response* object passed as argument. Any of these headers that are found are used to update t +he state of the $cookie_jar.
    Hope this helps,
       larryk                                          
    perl -le "s,,reverse killer,e,y,rifle,lycra,,print"
    
Re: HTTP::Cookies is saving an empty file
by ropey (Hermit) on Jan 23, 2002 at 21:48 UTC
    I assume what your trying to achieve is just retrieve the cookies from whatever url you are visiting (because it needs cookies for user sessions ???) I did a similar thing a while back, which may/may not help
    my $url = shift; my $ua = new LWP::UserAgent; $ua->timeout(20); $ua->agent('Automated agent'); # with cookie support... my $cookies = HTTP::Cookies->new(); $ua->cookie_jar($cookies); my $req = HTTP::Request->new(GET => $url); print STDERR "doing GET request to $url...\n"; my $res = $ua->request($req); my $content = $res->content; my $status = $res->status_line(); $ua->cookie_jar->extract_cookies($res);
      Before you lose all hope be sure that the page you are 
      requesting actually sends a cookie. I was sure that mine did
       but IT DIDN'T it was actually an image that was on
       the page that was giving my (netscape) browser a cookie. So
       if you are having a hard time goto the command line and:
      
      GET -ed http://www.google.com
      
      to get the headers and if you dont see something like:
      
      Set-Cookie: PREF=ID=44fae06727e94467:TM=1056331233:LM=1056331233:
      S=bt-ZmWiBhxbwpt78; expires=Sun, 17-Jan-2038 19:14:07 GMT;
       path=/; domain=.google.com
      
      then keep trying pages until you do.
      douglasmj1 %%AT%% comcast %%DOT%% net