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

Dear monks,

Lately I've been using WWW::Mechanize to automate a good deal of my daily tasks. Today I've ran into a bit of a quandry. I need to interact with a site that prompts for HTACCESS authentication. I scoured WWW::Mechanize's documentation and couldn't find anyway to have Mechanize authenticate and continue.

I'm willing to do it "another way," so I've come to the monastery for advice. I need to be able to go to this page, authenticate, click a submit button and scrape the output [of the final page]. I'm no Perl guru, so I'm looking for a fairly easy to moderate way to do this.

Any help is *GREATLY* appreciated! Thanks!
  • Comment on Handling htaccess prompts with Mechanize (or something similar)

Replies are listed 'Best First'.
Re: Handling htaccess prompts with Mechanize (or something similar)
by ikegami (Patriarch) on Aug 31, 2005 at 21:51 UTC
    The docs say: "WWW::Mechanize is a proper subclass of LWP::UserAgent and you can also use any of LWP::UserAgent's methods." Use the credentials method.
Re: Handling htaccess prompts with Mechanize (or something similar)
by merlyn (Sage) on Aug 31, 2005 at 21:53 UTC
Re: Handling htaccess prompts with Mechanize (or something similar)
by mwp (Hermit) on Aug 31, 2005 at 21:52 UTC
    Check the WWW::Mechanize FAQ. You have pass the "Authorization" parameter to the Mechanize constructor. I believe that this might be inherited from LWP::UserAgent, but I was not able to confirm.

    alakaboo

Re: Handling htaccess prompts with Mechanize (or something similar)
by captkirk (Acolyte) on Sep 01, 2005 at 20:43 UTC
    Thanks for the tip fellas. Now I'd like to expand my original query. The credentials method works well :-), but I've ran into another snag. It looks like the page I'm trying to access is using NTLM authentication.

    I went ahead and installed LWP::Authen::Ntlm and Authen::NTLM (1.02) and modified my credentials statement to the following:

    $agent->credentials ( "host:port", '', 'myusername', 'password' );

    With LWP's debug enabled I see that NTLM authentication *is* being attempted. It tries to authenticate three times and comes back with a 401 HTTP error. I know my authentication credentials are correct, so I'm a bit stumped as to why it doesn't proceed.

    Once again, any help is greatly appreciated!