Solved

Submit HTML form via Perl

Posted on 2011-02-24
3
644 Views
Last Modified: 2013-12-25
Can anyone provide a short example (or link to one) demonstrating how (if possible) to submit form data to a Perl script at a url using Perl?

The purpose is to automate testing. The remote script requires basic authentication. Other then that the form data is basic.

Thanks in Advance.


0
Comment
Question by:kindaprog
3 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 34976652
0
 
LVL 5

Accepted Solution

by:
group0 earned 500 total points
ID: 34982465
Those links don't help because they don't describe doing form submission in combination with basic auth.  Here's an example:

use LWP::UserAgent;
use strict;

my $server = 'www.domain.com:80';
my $realm = 'example realm';
my $username= 'user';
my $password = 'pass';

my $ua = LWP::UserAgent->new;
$ua->credentials($server, $realm, $username => $password);
my $response = $ua->post('http://www.domain.com/form.cgi',
	{
		'param1' => 'value1',
		'param2' => 'value2',
		'submit' => 'submit',
	}
);
if ($response->is_success) {
	print $response->content . "\n";
} else {
	die($response->status_line);
}

Open in new window


Just modify the variables to match your form and auth setup, but be sure not to drop the port or add http:// in the $server variable, or auth will fail.
0
 

Author Closing Comment

by:kindaprog
ID: 35041727
Excellent. Thank you. Sorry I took so long getting back to you.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

747 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

10 Experts available now in Live!

Get 1:1 Help Now