I'm trying to write a Perl script that will go out to a website, log in, pull up a query page, fill-in and submit the query, extract a few specific lines from the query results, and finally place that output into a file.
I'm having difficulty with the log in portion. It appears that rather than using the built-in Apache authentication, the developer decided to write their own authentication scheme that uses cookies.
I setup a cookie jar but I'm not certain I'm actually getting and keeping the cookie. When I try to go to a page after the log in page I get an error saying I'm not logged in or my session has expired.
Here's the code as I have it thus far.
Code:
#!/usr/bin/perl
use strict;
use LWP;
use HTTP::Cookies;
my $url = 'https://www.space-track.org/perl/login.pl';
my $proxy = 'http://proxy:80';
# Create a useragent
my $ua = LWP::UserAgent->new;
# Set the proxy
$ua->proxy(['https'], $proxy);
# Setup my cookie jar
#$ua->cookie_jar( {} );
my $cookie_jar = HTTP::Cookies->new(
file => "/Perl/cookies.lwp",
autosave => 1,
);
$ua->cookie_jar( $cookie_jar );
# Post the username and password
my $res = $ua->post( $url ,
[
'username' => 'XXXXXXXX',
'password' => 'XXXXXXXX',
]
);
# Print out the response
print $res->content;
print "\n ***** \n";
$res = $ua->post(
'https://www.space-track.org/perl/id_query.pl'
);
print $res->content;
print "\n ***** \n";
Thanks for any help.
Tom
P.S. I had to sanitize a few things from my code. i.e. username and password