At 04:13 AM 2003-03-03 +0200, Hytham Shehab wrote: >hi guys, > am haveing trouble setting up my cookies using this module, and >particularly i don't understand how to use the set and scan routines. >if anyone can point me to a good tutorial i will be greatfull.
All I've ever needed to know about cookies is in here: http://search.cpan.org/author/GAAS/libwww-perl-5.69/lwptut.pod#Enabling_Cookies Namely: Enabling Cookies A default LWP::UserAgent object acts like a browser with its cookies support turned off. There are various ways of turning it on, by setting its cookie_jar attribute. A "cookie jar" is an object representing a little database of all the HTTP cookies that a browser can know about. It can correspond to a file on disk (the way Netscape uses its cookies.txt file), or it can be just an in-memory object that starts out empty, and whose collection of cookies will disappear once the program is finished running. To give a browser an in-memory empty cookie jar, you set its cookie_jar attribute like so: $browser->cookie_jar({}); To give it a copy that will be read from a file on disk, and will be saved to it when the program is finished running, set the cookie_jar attribute like this: use HTTP::Cookies; $browser->cookie_jar( HTTP::Cookies->new( 'file' => '/some/where/cookies.lwp', # where to read/write cookies 'autosave' => 1, # save it to disk when done )); That file will be an LWP-specific format. If you want to be access the cookies in your Netscape cookies file, you can use the HTTP::Cookies::Netscape class: use HTTP::Cookies; # yes, loads HTTP::Cookies::Netscape too $browser->cookie_jar( HTTP::Cookies::Netscape->new( 'file' => 'c:/Program Files/Netscape/Users/DIR-NAME-HERE/cookies.txt', # where to read cookies )); You could add an 'autosave' => 1 line as further above, but at time of writing, it's uncertain whether Netscape might discard some of the cookies you could be writing back to disk. -- Sean M. Burke http://search.cpan.org/~sburke/
