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;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.