Perl http post example


This is an example that shows how to issue an HTTP POST command/request to a web server from a Perl script.


The perl LWP module

LWP (short for “Library for WWW in Perl”) is a popular group of Perl modules for accessing data on the Web. It lets your programs download and extract information from the Web. The example below shows how to use LWP to send an HTTP POST request to a web server and print the result to the standard output.


Perl HTTP POST example

use  HTTP::Request::Common qw(POST);
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
 
my $req = POST 'http://example.com/page',
              [ field1 => 'value1', field2 =>'value2',field3=>'value3'];
 
print $ua->request($req)->as_string;

References



Labels: Wireless Internet Security Coding Network Monitoring