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

Help with cookie jar!

Thread Next
Siva Namburi
July 23, 2001 14:31
Help with cookie jar!
Message ID:
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.


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

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

     if ($response->is_error()) {
       printf "%s\n", $response->status_line;
     } else {
       $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,
       return $content;
     $retry = $retry - 1;

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About