1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#!/usr/bin/perl
# Script to emulate a browser for posting to a
# CGI program with method="POST".
# Specify the URL of the page to post to.
my $URLtoPostTo = "http://blog.pexiweb.be/demo/form/traitement.php";
# Specify the information to post, the form field name on
# the left of the => symbol and the value on the right.
my %Fields = (
"champ" => "Hello World !"
);
# As seen above, "@" must be escaped when quoted.
# If you want to specify a browser name,
# do so between the quotation marks.
# Otherwise, nothing between the quotes.
my $BrowserName = "This Be Mine";
# It's a good habit to always use the strict module.
use strict;
# Modules with routines for making the browser.
use LWP::UserAgent;
use HTTP::Request::Common;
# Create the browser that will post the information.
my $Browser = new LWP::UserAgent;
#$Browser->proxy(['http'], 'http://10.0.0.14:8080');
# Insert the browser name, if specified.
if($BrowserName) { $Browser->agent($BrowserName); }
# Post the information to the CGI program.
my $Page = $Browser->request(POST $URLtoPostTo,\%Fields);
# Print the returned page (or an error message).
print "Content-type: text/html\n\n";
if ($Page->is_success) { print $Page->content; }
else { print $Page->message; }
# end of script |
Partager