in reply to Re: LWP::UserAgent and Cookies
in thread LWP::UserAgent and Cookies

Just a note:

You don't need

$cookie_jar->extract_cookies( $response );
If cookie jar object is set for user agent object than user agent does this itself.

--
Ilya Martynov (http://martynov.org/)

Replies are listed 'Best First'.
Re^3: LWP::UserAgent and Cookies
by jczeus (Monk) on Oct 27, 2021 at 08:37 UTC
    This is a very old thread, but having just tried myself I noticed that the cookie is not set if I don't make that method call.

    Although not needed in my example, I used a file for saving the cookie just to check the session-ID, and the file stayed empty without that call. Any thoughts?

      This works fine for me:

      #!/usr/bin/env perl use strict; use warnings; use LWP::UserAgent; use HTTP::Cookies; use Test::More tests => 1; my $cookie_jar = HTTP::Cookies->new; my $ua = LWP::UserAgent->new; $ua->cookie_jar ($cookie_jar); my $response = $ua->get ('https://twitter.com/'); like $cookie_jar->as_string, qr/guest_id=/, 'Cookie retrieved';

      HTTP::Cookies 6.01, LWP::UserAgent 6.15.


      🦛

        For some strange reason, works now for me too. Probably a PEBKAC. Thank you for your help.

        HTTP::Cookies 6.10, LWP::UserAgent 6.55.