Solved

Submit HTML form via Perl

Posted on 2011-02-24
3
648 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

22 Experts available now in Live!

Get 1:1 Help Now