Solved

Submit HTML form via Perl

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Else condition 9 23
remove computer from using logon script 17 38
Convert .csv to tab delimited text 11 33
Opening a new tab in IE using Powershell / HTML 2 19
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

840 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