Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re^3: Passing a cookie with LWP::UserAgent

by nedals (Deacon)
on May 26, 2005 at 02:12 UTC ( #460487=note: print w/replies, xml ) Need Help??

in reply to Re^2: Passing a cookie with LWP::UserAgent
in thread Passing a cookie with LWP::UserAgent

Hi raflach,
I struggled with this for a couple more hours and then went to plan 'B'

What I did was to get the cookie value in my initial script and pass it, via a post, to the LWP'd script. I modified my authenication subroutine (saved in a module), to accept first a cookie and, if that failed, get the cookie value from the posted data.

This works well and I do not have to worry about passing cookies. It also has an added bonus. I am now able to run my scripts if cookies are disabled by saving the cookie value in a hidden field.

Some day I'll understand how this cookie_jar thing works :-).

  • Comment on Re^3: Passing a cookie with LWP::UserAgent

Replies are listed 'Best First'.
Re^4: Passing a cookie with LWP::UserAgent
by kyoshu (Curate) on May 26, 2005 at 07:46 UTC
    you basicly need something like this: $ua->cookie_jar(HTTP::Cookies->new(file => "cookies.txt",autosave => 1));

    some code from some of my script (to ilustrate how it works):
    $ua = LWP::UserAgent->new;
    $ua->cookie_jar(HTTP::Cookies->new(file => "cookies.txt",autosave => 1));
    my $req = HTTP::Request->new(POST => '');
    my $res = $ua->request($req);
    my $req = HTTP::Request->new(GET => '
    my $res = $ua->request($req);
    my $data = $res->as_string;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://460487]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2021-05-14 20:04 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (150 votes). Check out past polls.