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

Hello, Normally I can work my way out of most problems, but this one has me banging my head. Using LWP, I can successfully save the cookies from any web page except ones that utilize a redirect. Here is a snippet of my relevant code. The header clearly displays the cookie, but I can not access it. Any suggestions are greatly appreciated...
use HTTP::Cookies; use LWP::UserAgent; my $ua = LWP::UserAgent->new; $request = HTTP::Request->new('GET', 'http://www.hotbot.com'); $response = $ua->simple_request($request); $cookie_jar = HTTP::Cookies->new(file => "cookie.txt", autosave => 1, +ignore_discard => 1); $cookie_jar->extract_cookies($response); print $response->as_string;

Replies are listed 'Best First'.
Re: LWP Cookies
by dws (Chancellor) on Aug 06, 2002 at 17:57 UTC
    Using LWP, I can successfully save the cookies from any web page except ones that utilize a redirect.

    Try creating the cookie jar before you making the initial request, and associate the jar with the user agent via   $ua->cookie_jar($cookie_jar); (also before you make the request).