Re: LWP::UserAgent and HTTP::Cookies

Gisle Aas (gisle@activestate.com)
18 Apr 2001 19:53:10 -0700


Matthew Hesher <hesher@cs.fsu.edu> writes:

> Can anyone tell me how to change LWP::UserAgents defautlt behavior from
> 'ignore cookeis' to 'get and set cookies'?  I've written a little script
> that looks like this:
> 
> $ua = LWP::UserAgent->new;
> $cookie_jar = HTTP::Cookies->new;
> $cookie_jar->clear();
> $ua->cookie_jar($cookie_jar);
> $request = HTTP::Request->new('GET',
> 'http://some.web-page.com/page1.asp');
> $response = $ua->request($request);
> print($cookie_jar->as_string());
> $request = HTTP::Request->new('POST',
> 'http://some.web-page.com/page2.asp');
> print($request->headers_as_string());
> $response = $ua->request($request);
> 
> 
> After the first request is fulfilled, the cookie-jar is filled with the
> cookies received from page1.asp.  I can see this from the first print
> statement above.  However, before sending the second message,  print the
> headers and  get nothing.  I've tried forcing the heads in there with
> '$cookie_jar->add_cookie_header($request)' and if I print the header
> after that, the $request header appears to be set with the cookie
> received from page1.asp, but page2.asp (which is lookie for the cookie
> from page1.asp) says it can't find the cookie.  Can anyone help me
> figure out what's going on.

It depends on what "some.web-page.com" actually is and various other
factors.  Running the script with:

   use LWP::Debug '+';

can give you some clues.  Otherwise if you can give us a runable
example we should be able to figure it out.  There should not be any
need for you to call the add_cookie_header() method.

Regards,
Gisle