Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Answer: How do post to a URL from a form and display the results in a browser?

by icuc (Initiate)
on Sep 13, 2000 at 07:15 UTC ( #32240=categorized answer: print w/replies, xml ) Need Help??

Q&A > CGI programming > How do post to a URL from a form and display the results in a browser? - Answer contributed by icuc

I think this , perhaps , could satisfy your need.
---------------------------

#!/user/local/bin/perl

use strict;
use CGI;
use HTTP::Request;
use LWP::UserAgent;

my $q = CGI->new();
$q->use_named_paramters(1);
my $var1 = $q->param('a');
my $var2 = $q->param('b');

my $ua = LWP::UserAgent->new();

my $method = "POST";
my $url = "http://where_you_want";

use HTTP::Header;
my $header = HTTP::Header->new();
my $content = "v1=".$var1."&v2=".$var2;
my $request = HTTP::Request->new($method, $url, $header, $content);

use HTTP::Response;
my $response = $ua->request($request);
if($response->is_success) {
print $response->content;
}
else {
print $response->error_as_HTML;
}
-------------------------------------
for more details, please check Perl's Documents HTTP::Request, HTTP::Header, HTTP::Response, LWP::UserAgent, etc.

  • Comment on Answer: How do post to a URL from a form and display the results in a browser?
Replies are listed 'Best First'.
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2020-04-09 07:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The most amusing oxymoron is:
















    Results (47 votes). Check out past polls.

    Notices?