Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: How to authenticate / login htaccess with WWW::Mechanize

by davido (Cardinal)
on Dec 21, 2004 at 22:23 UTC ( [id://416642]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Automatically fill out web forms from the command line
in thread Automatically fill out web forms from the command line

I posted about this a few weeks ago and bart helped me to find the answer. Here's an example snippet of how to authenticate an htaccess system with WWW::Mechanize:

use strict; use warnings; use WWW::Mechanize; my $agent = WWW::Mechanize->new( autocheck => 1 ); $agent->credentials( 'www.somesite.com:80', 'somerealm', 'user', 'password' ); $agent->get( 'http://www.somesite.com/index.html' ); print $agent->content();

It's important to use the port number in the credentials URL. The realm is also important to get right. You can usually see it as the title of the dialog box that pops up in your browser when you visit an htaccess-restricted site.


Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://416642]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-07-13 23:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.