cookie_jar is magic. When a user agent (e.g. your browser or your LWP::UserAgent program) is sent cookies, the site expects them echoed back in subsequent requests. However, a cookie can expire after a set amount of time, different sites will send different cookies - and expect only the ones they sent back. In fact different scripts at the same site will send different coookies and expect the right one sent back.
cookie_jar automates all this, including possibly saving cookies to a file for reading on subsequent execution.
Just extract from responses and add to requests - the cookie_jar does the heavy lifting.# UNTESTED SNIPPET use LWP::UserAgent; $ua = new LWP::UserAgent; use HTTP::Cookies; $cookie_jar = HTTP::Cookies->new; $init_url = 'http://www.domain.com/cgi-bin/whatever.pl?X'; $request = new HTTP::Request('GET', $init_url); $cookie_jar->extract_cookies($response); # later.... $request = new HTTP::Request('GET', 'http://www.domain.com/cgi-bin/wha +tever.pl?Y'; $cookie_jar->add_cookie_header($request); $response = $ua->simple_request($request);
In reply to Re: What is a Cookie Jar?
by bobn
in thread What is a Cookie Jar?
by rjahrman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |