Dear LWP wizads!

 

I began my usage of cookies support in LWP (libwww-perl ver. 5.836) under
Perl, (v5.10.1 for MSWin32-x86-multi-thread) as follows without the
commented-out code:

 


  use LWP::UserAgent;

  use HTTP::Cookies;

  

  ...

  

  my $browser = LWP::UserAgent->new();

 

  my $cookies_file = 'LWP_Cookies.lwp';

  my $cookie_jar = HTTP::Cookies->new({file => $cookies_file, autosave =>
1});

  # $cookie_jar->load($cookies_file);

  $browser->cookie_jar($cookie_jar);

  # $cookie_jar->add_cookie_header($browser);

  

  #  ... some browsing code, including:

  my $response = $browser->get($url_canonical);

 

  # $cookie_jar->extract_cookies($response);

  # $cookie_jar->save($cookies_file);

 

The result was that the file 'LWP_Cookies.lwp' was created but empty,
despite the HTTP server issuing a "Set-Cookie: xyz" header line. The file
contains just the following text:

 

  #LWP-Cookies-1.0[\n]

  [eof]

 

(The square brackets signify new-line and end-of-file, respectively, not
literal text.)

 

Obviously, since the file is empty, on repeat GET requests from that site no
cookies were sent as part of the GET HTTP header. 

 

Question #1: Should the minimal code above be enough to save received
cookies and to retrieve and send cookies?

 

I then added the above commented out calls to the
$cookie_jar->load($cookies_file) and $cookie_jar->save($cookies_file)
methods with no discernable change.

 

Question #2: aren't these methods superfluous here?

 

I then added the $cookie_jar->extract_cookies($response); statement right
before the cookie jar save statement. This didn't change anything either.
The 'LWP_Cookies.lwp' file was still created empty!

 

I also tried to add $cookie_jar->add_cookie_header($browser) to the request
preparation. That in turn caused an error message "Can't locate object
method "uri" via package "LWP::UserAgent" at
C:/Perl/site/lib/HTTP/Cookies.pm line 42."

 

Question #3: What is wrong with the invocation of this cookie_jar method?

 

And generally, what do I do wrong?

 

Regards

Meir

 

 

 

Reply via email to