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);
|