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

O monks, I beseech thee: Is this not the proper code for
1. Storing a session cookie based on login/pass, then
2. fetching a pdf?
Also, I have SSL properly installed.
#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; use HTTP::Request::Common qw(POST GET); use HTTP::Cookies; # Tells me result of $ua->request sub tell_me { my $op = shift @_; if ($op->is_success) { print "Connection OK!"; } else { print $op->status_line . "\n"; } } #important variables my $document_url = shift; my $login_url = 'https://www2.lib.purdue.edu:2443/login'; my $pass = shift; my $user = shift; # Set up LWP browser, set up temporary and empty cookie jar my $ua = LWP::UserAgent->new; $ua->agent('Mozilla/5.0'); $ua->cookie_jar( {} ); # POST the username and password , and (hopefully) store resultant se +ssion cookie my $req = $ua->request(POST $login_url, [user => $user, pass => $pass] +) ; tell_me($req); # GET the document I want $req = $ua->request(GET $document_url, ':content_file' => $file_name); tell_me($req); exit 0;

Replies are listed 'Best First'.
Re: Document Fetcher
by Corion (Patriarch) on Mar 01, 2007 at 08:01 UTC

    At a glance it looks fairly well, but as you don't tell us what's going wrong, it's hard to tell you where the problems might be. I use WWW::Mechanize for browser emulation - that does all the cookie handling for me.

    If you don't have Crypt::SSLeay installed, https:// URLs might not work for you and you'll get a 500 error from LWP for that. But again, as you don't tell us anything about the errors you're seeing, it's hard to tell.

    Maybe the problem is that you never define $file_name anywhere. Knowing about the errors you're seeing would help confirm that.