Gossamer Forum
Home : General : Perl Programming :

using a script to simulate form action="post"

Quote Reply
using a script to simulate form action="post"
I want to to be able to add a sub-routine to a cgi script that will send some variables in that script to another script simulating action=post in forms.

I can do it in php, it is very easy:

http://www.phpbuilder.com/mail/php3-list/199806/0856.php

but how do you do it in cgi? i couldn't find anything about this.

cheers

http://www.ASciFi.com/ - The Science Fiction Portal
Quote Reply
Re: using a script to simulate form action="post" In reply to
Define some variables:

Code:

my $variable1 = $in{'variable1'};
my $variable2 = $in{'variable2'};


Then in the subroutine call, use the following codes:

Code:

&somesub ($variable1, $variable2);


Regards,

Eliot Lee
Quote Reply
Re: using a script to simulate form action="post" In reply to
i don't think i made clear what i want. I want a script, which has some variables in it (say $username and $password already) to then transparently post a form to another site. This is for, example, a dual membership scheme so that if someone signs up on one site it signs you up on another. Have a look at the php link i gave they explain it better.

http://www.ASciFi.com/ - The Science Fiction Portal
Quote Reply
Re: using a script to simulate form action="post" In reply to
You're right...you did not explain yourself clear enough.

Good luck!

Regards,

Eliot Lee
Quote Reply
Re: using a script to simulate form action="post" In reply to
is this not easy? all these things are so easy to do in php, i just wish gossamer wrote php scripts instead of cgi !

http://www.ASciFi.com/ - The Science Fiction Portal
Quote Reply
Re: using a script to simulate form action="post" In reply to
use the LWP::Simple module.
then it's as simple as:
Code:
my $cgi_data = get("http://your.domain.com/cgi-bin/called_script.cgi?username=$username&password=$password");
easy comes with a price.

-g


s/(\d{2})/chr($1)/ge + print if $_ = '8284703280698276687967';
Quote Reply
Re: using a script to simulate form action="post" In reply to
See `perldoc lwpcook` or try this snippet:

Code:
use LWP::UserAgent;
$ua = LWP::UserAgent->new;

my $req = HTTP::Request->new(POST => 'http://www.perl.com/cgi-bin/BugGlimpse');
$req->content_type('application/x-www-form-urlencoded');
$req->content('match=www&errors=0');

my $res = $ua->request($req);
print $res->as_string;
Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: using a script to simulate form action="post" In reply to
thanks everyone, i will try those and see how it goes :)

http://www.ASciFi.com/ - The Science Fiction Portal
Quote Reply
Re: using a script to simulate form action="post" In reply to
Hi Alex,

Your script works very well. When i log, i get this messages before the post result:

HTTP/1.1 200 OK Connection: close Date: Thu, 22 Feb 2001 15:08:05 GMT Server: Apache/1.3.12 (Unix) PHP/3.0.15 Content-Type: text/html Client-Date: Thu, 22 Feb 2001 15:10:56 GMT Client-Peer: 200.213.36.28:80

After that message i get the correct result.

Q: How can i get just the post result and not this message?

Here is the code:

#!/usr/bin/perl

use LWP::UserAgent;

$ua = LWP::UserAgent->new;

my $req = HTTP::Request->new(POST => 'http://www.myserver/script.cgi');
$req->content_type('application/x-www-form-urlencoded');
$req->content('user=xxx&pass=yyy');

my $res = $ua->request($req);

print "Content-type:text/html\n\n";
print $res->as_string;

Tia,

Kco

Quote Reply
Re: using a script to simulate form action="post" In reply to
I already got the answer,

Just change:
print $res->as_string;

to

print $res->content;

;)