hi...

i'm trying to deal with recieving/transferring cookies. i have the following
code segment that works in another case, but i can't seem to figure out what
i've done wrong...

basically, i'm trying to extract/save the cookie. displaying the headers
indicates that i have a cookie/array, although i can't figure out how to
read it.. but using the extract_cookie method, doesn't seem to save the
cookie to my cookie.txt file...

there's something simple that i'm missing...

any comments/pointers/criticisms would be appreciated...

thanks

-bruce


#############################################################
#!/usr/bin/perl -w

use strict;

use HTML::TreeBuilder;
use LWP::UserAgent;
use URI::Escape;
use WWW::Mechanize;
use LWP::Simple;
use URI::URL;
use HTTP::Cookies;

   my $ua = new LWP::UserAgent;
   $ua->timeout(30);
   $ua->agent("Mozilla/4.0 (compatible; MSIE 4.01; Windows95)" .
$ua->agent);

   my $cookie_jar = HTTP::Cookies-> new(
                    file => "cookie.txt",
                    autosave => 1,
   );
   $ua->cookie_jar($cookie_jar);


   # go ahead and get the selection page within the frame..
   # use www::machanize
   my $agent = WWW::Mechanize->new();
   $agent->cookie_jar($cookie_jar);

   $agent->get($host_url);


   my $host_url = "http://isis2.uiowa.edu/isis/chg_session/courses";;
   my $base_url = "http://isis2.uiowa.edu/isis/courses";;
   my $course_url = "https://isis2.uiowa.edu/isis/chg_session/doit";;


   #
   # this ua is setup with a cookie jar to be used throughout
   # the app...
   #
   # every sub/routine uses this global "ua"...
   #
   my $ua = new LWP::UserAgent;
   $ua->timeout(30);
   $ua->agent("Mozilla/4.0 (compatible; MSIE 4.01; Windows95)" .
$ua->agent);

   my $cookie_jar = HTTP::Cookies-> new(
                    file => "cookie.txt",
                    autosave => 1,
   );
   $ua->cookie_jar($cookie_jar);


   #
   # go ahead and fill/init the cookie_jar..
   #
   my $req = new HTTP::Request GET => $host_url;
   $req->content_type('application/x-www-form-urlencoded');
   my $res = $ua->request($req);


   # go ahead and get the selection page within the frame..
   # use www::machanize
   my $agent = WWW::Mechanize->new();
   $agent->cookie_jar($cookie_jar);

   $agent->get($host_url);


   my $semester = "20043";

   $url = $url."?next=courses&session=".$semester;

   my $req = new HTTP::Request GET => ($url);
   my $res = $ua->request($req);


##############################################
#
# printing/testing key/header information
#
##############################################

  foreach (keys %{$res->headers()})
  {
     print "$_ = ", $res->headers()->{$_}, "\n";
  }

   print "agent->location = ". $res->headers()->{'location'}. "\n";
   print "agent->base = ". $res->base(). "\n";

   print " testing\n";
   print "cookie test...".$res->headers()->{'set-cookie'}."\n";

   my %hdr = $res->headers()->{'set-cookie'};


   my $key;
foreach $key (keys (%hdr))
{
  my %qq = $key;
  print " test k = ". $hdr{$key} ."\n";
}
#print " ss ="[EMAIL PROTECTED]"\n";
print " xxxxx\n";
$cookie_jar->extract_cookies($res);
 $cookie_jar->save();
die;


Reply via email to