Hi Siva.  Why do you say it doesn't work?  Have you tried
dumping the cookie object using the as_string() method to
see where the problem is?

You shouldn't need the add_cookie_header() and extract_cookies()
calls.

Maurice

On Mon, Jul 23, 2001 at 02:31:08PM -0700, Siva Namburi wrote:
> 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;
>   }
> 

Reply via email to