LWP::UserAgent uses HTTP::Cookies to create cookies. HTTP::Cookies has 4 ways for you to load a cookie:

1. Load it from an LWP-format file, a format known as "Set-Cookie3". This is impractical, since the format is not documented anywhere that I can find.

2. Set it using HTTP::Cookies->set_cookie( $version, $key, $val, $path, $domain, $port, $path_spec, $secure, $maxage, $discard, \%rest ). The documentation says,

"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".

To use this, I would need to know what the arguments $path_spec and $discard mean, what $version should be set to, and what to set $port to if I want the cookie to work for any port, as cookies generally do.

3. Create the cookie in Firefox and load it from the resulting Netscape-format file. This is impossible, since Firefox and Chrome now both store cookies in sqlite.

4. Create a Netscape cookie by hand in a file, using the file format given here: http://www.cookiecentral.com/faq/#3.5

Then load this in like so: my $cookieJar = HTTP::Cookies::Netscape->new(file => 'cookies.netscape');

When I do this, with the file

.foo.net\tTRUE\t/\tFALSE\t1755828131\tcookie_name\ttrue
where \t is a tab, I get the error message
cookies.netscape does not look like a netscape cookies file at /usr/li +b/perl5/site_perl/5.14/HTTP/Cookies/Netscape.pm line 21, <FILE> line +1.

How do you create a cookie to use with LWP::UserAgent?


In reply to Cannot create a cookie using HTTP::Cookies by shagbark

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.