Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^4: Simulating --keep-session-cookies wget option with LWP ?

by i5513 (Pilgrim)
on Sep 27, 2011 at 11:28 UTC ( #928067=note: print w/replies, xml ) Need Help??

in reply to Re^3: Simulating --keep-session-cookies wget option with LWP ?
in thread Simulating --keep-session-cookies wget option with LWP ?

Ok, I tested your script with google and it works.

Then it maybe related with tomcat auth issue:
I changed your script to work with my tomcat manager:

use strict; use HTTP::Cookies; use LWP::UserAgent; # try to simulate wget: my $cookie_jar = HTTP::Cookies->new( file => "mycookie-tomcat.cookie", autosave => 1, ); my $ua = LWP::UserAgent->new; $ua->credentials ("host:8080","Tomcat Manager Application","user","pas +sword"); $ua->timeout(2); $ua->cookie_jar($cookie_jar); #$ua->env_proxy; if( !@ARGV) { warn "Requesting page"; my $request= HTTP::Request->new (GET=> "http://host:8080/manager/statu +s?XML=true"); my $status=$ua->request ($request); if ($status->is_success) { print $status->decoded_content(); } else { print STDERR $status->status_line, "\n"; return 1; } }; use Data::Dumper; warn "Cookies in jar:"; $cookie_jar->scan(sub { warn Dumper \@_ });
And then it printout cookie when I launch without parameters:
... $VAR1 = [ 0, 'JSESSIONID', '', '/manager', 'host.local', undef, 1, undef, undef, 1, {} ]; ...

but file of cookie is empty:

$ cat mycookie-tomcat.cookie #LWP-Cookies-1.0

I discover in tcpdump / wireshark, tomcat is returning first an 401 error with "You are not authorized to view this page. If you have not changed ...", setting a cookie wich is used by lwp after (it try again the access and the page is loaded correctly), but seems like not saved in the file

Thank you !
PD: What is wrong with my question, so I'm getting negative reputation ?

Replies are listed 'Best First'.
Re^5: Simulating --keep-session-cookies wget option with LWP ?
by Corion (Pope) on Sep 27, 2011 at 11:34 UTC

    Your cookie looks like this:

    $VAR1 = [ 0, 'JSESSIONID', '', '/manager', 'host.local', undef, 1, undef, undef, 1, {} ];

    The HTTP::Cookies documentation says about the format:

    0 version 1 key 2 val 3 path 4 domain 5 port 6 path_spec 7 secure 8 expires 9 discard 10 hash

    The ninth parameter, discard is 1 in your cookie. Why do you think that HTTP::UserAgent should save this cookie into a file?

    As to your "negative" reputation, your nodes are currently at "-1" and "0" respectively. I downvoted both of them, because you did not do show any relevant code first, and then did no work on making the problem easily reproducible outside your specific environment.


      Thank you clarifying that issue, using ignore_discard attribute in HTTP::cookies, made the code works.

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

      I don't know if can be future problems with this option enabled. In my case (pooling tomcat manager I suppose that should not be any problem).

      Thank you again
      PD: I hope this node doesn't appear two times, if so , sorry

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://928067]
and snow settles gently...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2017-10-18 04:55 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (242 votes). Check out past polls.