<?xml version="1.0" encoding="windows-1252"?>
<node id="922420" title="Mechanize and Cookie Confusion" created="2011-08-25 14:03:07" updated="2011-08-25 14:03:07">
<type id="115">
perlquestion</type>
<author id="961">
Anonymous Monk</author>
<data>
<field name="doctext">
I am trying to understand how cookie work. Pleas forgive my ignorance.

&lt;code&gt;
#!/usr/bin/perl

use strict;
use WWW::Mechanize;
use Data::Dumper;

my $url = 'http://www.google.com';
my $m   = WWW::Mechanize-&gt;new( autocheck =&gt; 0 );
$m-&gt;cookie_jar( HTTP::Cookies-&gt;new() );

my $response = $m-&gt;get( $url );

## Do I need to do this?
my $extract_cookie = $m-&gt;cookie_jar-&gt;extract_cookies( $response );
$m-&gt;cookie_jar-&gt;add_cookie_header( $extract_cookie );

my $request = $m-&gt;get( $url );
print Dumper \$request;

&lt;/code&gt;
Questions:
&lt;li&gt;When I create a cookie jar, does it mean that Mechanize will be using the cookie throughout the session? 
&lt;li&gt;Do I even need to extract the cookie information and try to add it in the request header? If yes, the above code does not work when I try to add the cookie into the header. 
&lt;li&gt;What do you use to see what you are sending an http request through Mechanize? For example, do you use WireShark to see what you are sending? Is there something simpler?</field>
<field name="reputation">
5</field>
</data>
</node>
