develooper Front page | perl.libwww | Postings from July 2001

Help with cookie jar!

Thread Next
From:
Siva Namburi
Date:
July 23, 2001 14:31
Subject:
Help with cookie jar!
Message ID:
00e101c113be$c9d5f1c0$13e7020a@corp.clickarray.com
Hi ,

          I am trying to capture any cookies in the header (Set-Cookies:)
coming from the server and store them in a file. I also want to send the
saved cookies back to the server.
The following code is what i am doing. It does not seem to work. Shouldn't
$ua->cookie_jar($cookie_jar); do a get/set of the cookies? It does not work.
And load , add_cookie_header, extract_cookies and save do not help.

thanks,
siva

sub http_get()
 {

 $url = "http://$self->{vip}/$url";
 print "Do http get $url\n";
 my $ua = LWP::UserAgent->new();
 $ua->agent("Schmozilla/v9.14 Platinum");
 $ua->timeout(5);
 my $cookies = "/$ENV{HOME}/.lwp_cookies";
 $cookie_jar = HTTP::Cookies->new( File => $cookies, Autosave => 1 );
 my $req = HTTP::Request->new(GET => $url);
 my $response;
 my $retry = 10;
 $cookie_jar->load( );
 $ua->cookie_jar($cookie_jar);
 $cookie_jar->add_cookie_header($req);

 while ($retry) {
    $response = $ua->request($req);

     if ($response->is_error()) {
       printf "%s\n", $response->status_line;
       sleep(10);
     } else {
       $cookie_jar->extract_cookies($response);
       $cookie_jar->save($cookies );
       print "GET ", $url, "\n";
       my $content = $response->content();
       my $bytes = length $content;
       my $count = ($content =~ tr /\n/\n/);
       printf "%s (%d lines, %d bytes)\n", $response->title(), $count,
$bytes;
       return $content;
     }
     $retry = $retry - 1;
  }


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About