Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Maybe (I'm allmost convinced) that I the solution is quite easy but I can't see it.

I successfully load a form using UserAgent $ua.
With it comes a cookie that must be valid for the whole session.
I fillout the form and submit it by creating a new UserAgent $ub.
Within this 2. request the cookie is cheked many, many times!
And if the values of $ub aren't the same as of the first one
a new one is set and finally my last form is not accepted.

Again: during the three Requests: 1. Form, 2. Form and the final Fail/Success_Page
the value of the first cookie are many times (seen in traffic dump) checked.

My question now: How can I easily set the cookies of $ub and $uc to $ua
without saving and loading ev.thing to a file? This does not work:
$ub->cookie_jar = $ua->cookie_jar;
Thanks for your patience, Carl
use HTTP::Cookies; .. $ua = LWP::UserAgent->new; $ua->agent($MOZILLA); $ua->cookie_jar(new HTTP::Cookies); $res = $ua->request(GET $url); #the $ua->cookie_jar is set hereafter $post = &fillForm(\$res, \%FW, $form); # fillout form # Creating a new UserAgent $ub $ub = LWP::UserAgent->new; $ub->agent($MOZILLA); $ub->cookie_jar(new HTTP::Cookies); $ub->cookie_jar = $ua->cookie_jar; #crash # now this cookie of $ub has to be the same as of $ua # I just don't get it and # I don't want to save and load a file due to permissions $res = $ub->request($post); $post = &fillForm(\$res,\%FW,'msgO',$nSMS); # fillout next Form # create 3rd UserAgent $uc $uc = LWP::UserAgent->new; $uc->agent($MOZILLA); $uc->cookie_jar(new HTTP::Cookies); $uc->cookie_jar = $ub->cookie_jar; #crash # Again this cookie must be the same as # the 2 others before $res = $uc->request($post); ...

Replies are listed 'Best First'.
•Re: How can I set: $ub->cookie = $ua->cookie ?
by merlyn (Sage) on Aug 22, 2002 at 15:54 UTC
    Stop creating new cookie jar objects!
    my $jar = HTTP::Cookies->new; ... $ua = LWP::UserAgent->new; $ua->cookie_jar($jar); ... $ub = LWP::UserAgent->new; $ub->cookie_jar($jar); ... $uc = LWP::UserAgent->new; $uc->cookie_jar($jar); ...
    There. Now they all share the same jar.

    -- Randal L. Schwartz, Perl hacker

      Thanks Randal, that's it,
      Carl
Re: How can I set: $ub->cookie = $ua->cookie ?
by fglock (Vicar) on Aug 22, 2002 at 15:30 UTC

    This might work, but it breaks "object encapsulation" so don't do that.

    $uc->{cookie_jar} = $ub->{cookie_jar};