[Memphis.pm] Submitting Form Data

Brock Sides philarete at mindspring.com
Fri Mar 17 19:55:35 CST 2000


Matt Bledsoe wrote:
> 
> I'm trying to make a perl script that will submit data to a cgi as if I had
> clicked a button on the web site to do the same.  It's got me stumped and
> those two linux journal pages didn't help me much either.  Any ideas?
> 
> Matt

You need the libwww bundle.

http://www.cpan.org/modules/by-module/Bundle/libwww-perl-5.47.tar.gz

Then you do something like this:

#!/usr/bin/perl -w

use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;

# The content of the POST or GET
my $content='var1=foo&var2=baz&var3=quux';

my $ua = new LWP::UserAgent;

my $request = new HTTP::Request 'POST',
'http://www.example.com/cgi-bin/foo.cgi';
$request->header('Content-type' => 'application/x-www-form-urlencoded');
$request->header('Content-length' => length($content) );
$request->add_content($content);

# Or if you're doing a GET:

# my $request = new HTTP::Request 'GET',
"http://www.example.com/cgi-bin/foo.cgi&$content";

my $response = $ua->request($request);

__END__

Then you've got the content returned by the cgi in $response.

If you want to get really fancy, pick up the O'Reilly Pelican book, "Web
Client Programming in Perl".

libwww also includes GET, HEAD, and POST, which are free standing perl
scripts installed into /usr/bin, and which let you knock out quick shell
scripts, or do grab web content from the command line. I couldn't do
without them.

> BTW exactly how many people are on this list?  I haven't seen much happening
> on it =)

There are 15 email addresses subscribed to the list. Two of which are
mine. You can find this out by issuing the command "who memphis-pm-list"
to majordomo at pm.org.

Brock Sides
bsides at towery.com
philarete at mindspring.com
----------------------------------------------------------------------------
To unsubscribe, please send email to majordomo at pm.org
with 'unsubscribe memphis-pm-list' in the body of the message.
----------------------------------------------------------------------------




More information about the Memphis-pm mailing list