in reply to What is a Cookie Jar?
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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: What is a Cookie Jar?
by Anonymous Monk on Jul 04, 2003 at 17:25 UTC | |
by bobn (Chaplain) on Jul 04, 2003 at 18:40 UTC |