mikes300 has asked for the wisdom of the Perl Monks concerning the following question:

Attempting to login to a password-protected site (Apache Tomcat manager application such as http://www.xxx.com:8082/manager) and it gives a pop-up password prompt. I have seen some posts here regarding automating id/pwd if i know the variable names i will be posting to but i'd be stuck going through tomcat source code to try and figure that out. I can make a http request just fine to a non-pwd protected site using UserAgent and HTTp request, so at least I am that far. Any way to just give the pop up form two pieces of data (id & password), regardless of what their variable names are and then it would read the response? Perhaps I am approaching this all wrong!!

Replies are listed 'Best First'.
Re: Getting past a password prompt in perl
by Plankton (Vicar) on Feb 04, 2009 at 23:30 UTC
Re: Getting past a password prompt in perl
by missingthepoint (Friar) on Feb 05, 2009 at 05:31 UTC

    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
      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