New with libwww-perl and am stuck trying to POST a form.

Posted on 2007-12-01
Last Modified: 2008-03-04
I am new to libwww perl, and am trying to POST a request, and I am just frustrating myself at this point.

I am trying to write a UA (User Agent) to login to our Barracuda anti-spam box so it can gather some stats.

I can access the initial URL where the login screen is.  I can gather and populate the form fields using HTML::Form.  But when I try to POST the filled out form back, I always get a 302 result code ("Moved").  This happens whether I use the correct or incorrect password.  The 'Content' string LWP is passing back looks the same as the one I grabbed with a packet sniffer when I accessed the system with my browser.

I could just use some help in figuring this out.  Let me know what else would be useful to post and I'll post it.


use strict;

use warnings;

use LWP::UserAgent;

use HTML::Form;

my $p;

my $domain       = '';

my $barracuda    = "barracuda.$domain";

my $cookies      = "/tmp/$barracuda";

my $from         = "fines\@$domain";

my $proto        = 'http';       # change to 'https' if using https

my $url          = "$proto://$barracuda/cgi-bin/index.cgi";

my $user = 'admin';

my $password='secret';

$p->{host}       = "$proto://$barracuda";

$p->{timeout}    = 60;

$p->{agent}      = 'LWP 5.808';

my $ua = LWP::UserAgent->new;


my $response = $ua->get($url);

if ($response->is_success) {

    print $response->content;  # or whatever

} else {

    die $response->status_line;


print "code is " . $response->code . "\n";

print "message is " . $response->message . "\n";

my @forms = HTML::Form->parse($response);

my $form=$forms[0];

print "this form has this many inputs: " . $form->inputs . "\n";



my $enc_key=$form->value('enc_key');

my $et=$form->value('et');

my $request=$form->click;

$request->header(Host => '');

print "content is " . $request->content . "\n";

my $c=$request->content;

$c .= "&password_entry=";


$request->header('Content-length' => length($c));


$request->header('User-Agent' => $p->{agent});

$request->header('Accept' => 'text/html');

print "content is " . $request->content . "\n";

print "request is:\n" . $request->as_string . "\n";


print "code is " . $response->code . "\n";

print "message is " . $response->message . "\n";

Open in new window

Question by:mactfines
LVL 28

Accepted Solution

FishMonger earned 500 total points
Comment Utility
It might be easier/better to use a different approach/module.

use WWW::Mechanize;

Expert Comment

Comment Utility
Forced accept.

EE Admin

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now