Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I manually add cookies to WWW::Mechanize's already existing cookiejar

I have a perl script where after fetching a page I need to add a cookie to an already existing cookiejar with cookies in it already. how do I go about doing this? I'm hoping for a python mechanize style .set_cookie() function

like image 848
Joe Schmoe Avatar asked Jan 21 '23 12:01

Joe Schmoe


1 Answers

A WWW::Mechanize object isa LWP::UserAgent, which has a cookie_jar attribute that normally contains a HTTP::Cookies object, which has a set_cookie method.

So you'd do something like:

$mech->cookie_jar->set_cookie( $version, $key, $val, $path, $domain, $port,
                               $path_spec, $secure, $maxage, $discard, \%rest )

The set_cookie() method updates the state of the $cookie_jar. The $key, $val, $domain, $port and $path arguments are strings. The $path_spec, $secure, $discard arguments are boolean values. The $maxage value is a number indicating number of seconds that this cookie will live. A value <= 0 will delete this cookie. %rest defines various other attributes like "Comment" and "CommentURL".

like image 196
cjm Avatar answered Feb 16 '23 03:02

cjm