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

which functions and modules are necessary to login to a web page and download a few pages that you have to be logged in to get. The site uses the post method to read the user name and password. I was thinking LWP and HTTP but there are so many functions i just get lost trying to figure out what each one does... a little guidence would be appreciated.

Edit kudra, 2002-06-23 Changed title

Replies are listed 'Best First'.
Re: login???
by zentara (Cardinal) on Jun 22, 2002 at 20:24 UTC
    Try something like this:
    use HTTP::Request; use LWP::UserAgent; use strict; my $ua = LWP::UserAgent->new; my $req = HTTP::Request->new(POST=>'http://192.168.0.1/authtest/index. +html'); $req->authorization_basic('yourname', 'password'); my $content = $ua->request($req)->as_string; print "Content is $content";
      i tried this to experiment... the goal was to get the content of my default page once ive logged in into $content
      #!/usr/bin/perl use strict; use HTTP::Request; use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $req = HTTP::Request->new(POST=>'http://perlmonks.com/index.pl'); $req->authorization_basic('maddfisherman', '********'); my $content = $ua->request($req)->as_string;
      but this just gives me the default page not my page after i log in.
        Perlmonks doesn't use web server authorization like that. It's all cgi script-based authentication based on cgi params or cookies.
        # UNTESTED use HTTP::Request; use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $req = HTTP::Request->new(POST=>'http://perlmonks.com/index.pl?op=l +ogin;user=maddfisherman;passwd=******'); my $content = $ua->request($req)->as_string;
        And if you're thinking of writing a votebot, don't. :)
Re: login???
by Marza (Vicar) on Jun 22, 2002 at 20:24 UTC
Re: login???
by Zaxo (Archbishop) on Jun 22, 2002 at 20:27 UTC

    Look into the http server's basic authentication methods. You don't need to do any scripting for that, except for initial signup. Auth is a CPAN search which should give you plenty of ideas.

    After Compline,
    Zaxo