in reply to Getting past a password prompt in perl

Use WWW::Mechanize. It's a subclass of LWP::UserAgent, so you get all of LWP::UA's functionality and then some. Perhaps something like this would work for you:

use strict; use warnings; use WWW::Mechanize; my $mech = WWW::Mechanize->new; $mech->credentials("www.xxx.com:8082", "Tomcat Manager App Realm yada" +, "username", "password"); $mech->get("http://www.xxx.com:8082/manager");

Life is denied by lack of attention,
whether it be to cleaning windows
or trying to write a masterpiece...
-- Nadia Boulanger

Replies are listed 'Best First'.
Re^2: Getting past a password prompt in perl
by mikes300 (Initiate) on Feb 05, 2009 at 17:21 UTC
    I have something close to that but not getting through....imagine it is something to do with my credentials statement but i know the user/pass combo works

    use WWW::Mechanize; use HTTP::Request; sub httprequest { my $mech = WWW::Mechanize->new(autocheck => 1); $mech->credentials("servername:8082", "Tomcat Manager", "username", "p +assword"); $mech->get("http://servername:8082/manager/status/all"); print $mech->content();

    $ perl to*

    Error GETing http://stltcat04:8082/manager/status/all: Unauthorized at tomcatQA.pl line 13

      Are you posting the actual code you're running (presumably tomcatQA.pl)? If not, please do.

      Maybe try the following (add before your print $mech->content()) and post the output here?

      use Data::Dumper; print Dumper $mech->response; # dump returned HTTP::Response object

      One other thing - you don't need to explicitly use HTTP::Request because WWW::Mechanize will use it for you.


      Life is denied by lack of attention,
      whether it be to cleaning windows
      or trying to write a masterpiece...
      -- Nadia Boulanger
        It seems I get the 401 unauthorized as well. So not sure if this is valid solution? Any help here ?
        my $mech = WWW::Mechanize->new; my $username = "user"; my $password = "pass"; my $host="somehost"; my $port="12001" $mech->credentials("$host:$port", "Tomcat Manager Application", "$ +username", "$password"); $mech->get("$url/manager/list"); print Dumper $mech->response; # print $mech->content();