How do I set a cookie to be passed in with my www::mechanize request?
I have set my cookies, but it seams that they are not getting added to the header.
Time is running out too, I have to have this ready for a client monday, any help would be very appreciated!
Heres my code.
#!/usr/bin/perl -w
use CGI::Carp qw(fatalsToBrowser);
use strict;
use WWW::Mechanize;
use HTTP::Cookies;
use LWP 5.64;
use LWP::Debug qw(+);
print "Content-type: text/html\n\n";
# creating a new cookie jar
my $mech = WWW::Mechanize->new();
my $url = 'http://www.kbb.com/KBB/UsedCars/2007_Acura_MDX.aspx';
$mech->cookie_jar(HTTP::Cookies->new());
$mech->cookie_jar->set_cookie(-name=>'PersistentZipCode',
-value=>'15213',
-host=>'www.kbb.com',
-expires=>'Thu, 04 Dec 2008 18:23:16 GMT',
-path=>'/'
-secure=>'false');
$mech->cookie_jar->set_cookie(-name=>'ZipCode',
-value=>'15213',
-host=>'www.kbb.com',
-expires=>'+2h',
-path=>'/',
-secure=>'false');
# build a request object
my $request = $mech->request->(GET => $url );
$mech->cookie_jar->add_cookie_header($request);
$mech->get($url);
print $mech->content();
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.