Solved

Submit HTML form via Perl

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
email validation 9 49
Find unused columns in a table 12 75
How do I add counter to html listbox using jquery 2 26
Convert Variable to Array 4 16
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Find out what you should include to make the best professional email signature for your organization.
The viewer will learn how to dynamically set the form action using jQuery.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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