I assume that you are using LWP::UserAgent to do the server communication. If you're not doing this, think about doing this. The only drawback of LWP::UserAgent is, that it is not in the Perl distribution, but we have may documents in the monastery detailing how to install modules (even if you don't have administrative privileges) - use the Super Search and search for module and install or something like that.

If you're using LWP::UserAgent, there is the module HTTP::Cookies and the method $agent->cookie_jar() of your useragent. Just get the cookie jar from the useragent, fill it with the right cookie(s), and that would be it.

As an additional extra, you get proxy support for free with LWP::UserAgent.

Here's some untested code to manipulate cookies of UserAgent :

use strict; use LWP::UserAgent; use vars qw($ua, $request, $response, $cookie_jar, $URL); $ua = new LWP::UserAgent; # Read proxy settings from the environment, if given $ua->proxy(); $request = new HTTP::Request($URL); $response = $ua->request( $request ); $cookie_jar = new HTTP::Cookies; $cookie_jar->extract_cookies($response); # Tell $ua to use our cookie jar : $ua->cookie_jar($cookie_jar); # Make our cookies persistent $cookie_jar->save("cookie_jar"); $ua->cookie_jar($cookie_jar);

In reply to Re: Sending Post Forms and Cookies by Corion
in thread Sending Post Forms and Cookies by Martin A

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.