Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 05-05-2011, 02:55 PM   #1
LQ Newbie
Registered: Jun 2008
Location: USA
Distribution: Ubuntu, OpenSUSE, RedHat
Posts: 20

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.

use strict;
use LWP;
use HTTP::Cookies;

my $url = '';
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(

print $res->content;
print "\n ***** \n";
Thanks for any help.


P.S. I had to sanitize a few things from my code. i.e. username and password
Old 05-05-2011, 04:33 PM   #2
Sergei Steshenko
Senior Member
Registered: May 2005
Posts: 4,481

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

path make sense ?
Old 05-09-2011, 10:27 AM   #3
LQ Newbie
Registered: Jun 2008
Location: USA
Distribution: Ubuntu, OpenSUSE, RedHat
Posts: 20

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.


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

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

All times are GMT -5. The time now is 02:52 PM.

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