in reply to HTTP::Cookies with LWP::UserAgent

There are two more methods you can try, the first is to use Netscape cookies (if you use Netscape):
my $file = "$ENV{HOME}/.netscape/cookies"; $ua->cookie_jar( HTTP::Cookies::Netscape->new( file => $file, autosave => 1, ) );
or you could skip writing the cookie to a file. You didn't mention that you _need_ to save the cookie for later use. If you really only need to cookie around for the life of the script, then just use RAM:
$ua->cookie_jar(new HTTP::Cookies);

Jeff

R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
L-L--L-L--L-L--L-L--L-L--L-L--L-L--

Replies are listed 'Best First'.
Re: (jeffa) Re: HTTP::Cookies with LWP::UserAgent
by dkode (Acolyte) on Jun 01, 2001 at 04:34 UTC
    Is there a way to save the cookie for later use? Or is that not possible when using LWP::UserAgent? Whenever it sends a request does it tell the server where to locate the cookie at? Thanks in advance.
      Yes, you can save the cookie to a file by specifying a file name when you create the cookie object. If you only need the cookie around for the session, then you don't need to save it, unless you don't want to re-create it next time you run your bot.

      When a request is sent to the server, the cookie is neatly tucked away in the header of the request. That's how the server gets the cookie - through the browser (or the web bot in our case), which creates the header for the request.

      Jeff

      R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
      L-L--L-L--L-L--L-L--L-L--L-L--L-L--
      
        OK, so with my script i specify a file so that each request that is sent the server knows where to locate the cookie. In that case, Why would the server send a response saying it could not set a cookie even though it is set to the cookies.txt file? Is it possible that the server only allows IE and Netscape browsers ( I have the ua set as Mozilla/4.0) I'm still stumped as to why it would not set this cookie. Very stange.