LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 05-05-2011, 01:55 PM   #1
saldon
LQ Newbie
 
Registered: Jun 2008
Posts: 14

Rep: Reputation: 0
Interacting with a website using Perl and LWP


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
 
Old 05-05-2011, 03:33 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
I haven't read the documentation, but does

Code:
"/Perl/cookies.lwp"
path make sense ?
 
Old 05-09-2011, 09:27 AM   #3
saldon
LQ Newbie
 
Registered: Jun 2008
Posts: 14

Original Poster
Rep: Reputation: 0
The path is not really relevant and I'm certain that is not the problem. I'm building the script in my home directory and the cookie file is actually in the same directory as the script itself. I just changed the path in my posting from the actual path I used for security reasons. I don't think sharing my username with the world is a good idea.
 
  


Reply

Tags
cookies, perl


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl with LWP and NTLM wondergirl Programming 3 05-22-2010 02:32 PM
Perl Error LWP/Simple.pm netpumber Slackware 11 12-18-2008 12:06 AM
Perl install LWP module ; problems ... danran Programming 5 05-03-2007 01:02 PM
Perl's LWP to Python?? chutsu Programming 3 06-05-2006 12:55 PM
interacting with prompt quarry_06 Programming 8 08-03-2005 12:24 AM


All times are GMT -5. The time now is 07:30 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration