Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ARRGGG How do i simulate a form post within PERL? 1

Status
Not open for further replies.

Flappy

Programmer
Jul 30, 2002
35
0
0
AU
i just cannot find information on this anywhere!

i have a form on a webpage that calls my CGI PERL script, my script processes the passed variables and saves them, but then i need my PERL script to submit a form off to another website.

can this be done???????

please help
 
Well, you might be able to make your script generate a new html-page with a form containing all the variables you want to submit to the other script. Then you enter an onLoad handler (javascript) for the page that pushes the "submit" button.

I'm nowhere near sure if this would work at all, and even if it did it's not exactly elegant =P

There should be a better solution, but right now my brain is tired, so I can't think of one ;)
 
If you just need to create a new web page with the data from your previous form, create an HTML page in perl and use the <INPUT> tags as normal. Within the input tags, add 'VALUE=$vaule&quot; for each form field. Or, you can create a fork process and call another script passing the values as normal: There's always a better way...
 
Hi Flappy,

There should be no problem of calling a web page on another remote website. However, it seem to me you would need control over both sites in order to pass variables between the two scripts. You could have your site upload the file of saved variable to the remote site, or you could have the remote site download your file of save variables. Once the remote site had the file, it could incorporate the variable into its scripts whether they be VBA, java, perl, c or some other language. The script on the remote site would need to be written to specifically handle this.

Also, if the remote site script was written in perl it might be possible to call the perl script directly from your script and pass the variables as parameters. Since web site are designed specifically to allpw only the localhost to have access to its cgi-bin directory, any remote computer would have some serious permissions headaces in calling the remote perl script directly and passing the variable to it as parameters; however, anything is possible.

Another option would be to have a centralized database that both sites could use like MySQL or Postgres. Then the DBI connection string in the perl scripts would only need point to the host's web address passing username and password and port number to insert the variables into the database's table.


Leland F. Jackson, CPA
Software - Master (TM)
Nothing Runs Like the Fox
 
[tt]i have a form on a webpage that calls my CGI PERL script, my script processes the passed variables and saves them, but then i need my PERL script to submit a form off to another website.[/tt]

You can use the LWP module to make the http request to the second server.

This requests the front page from perl.com.
Code:
#!/usr/local/bin/perl
use LWP::Simple;
$url = '[URL unfurl="true"]http://www.perl.com/';[/URL]
$c = get($url);
$c =~ s/.*?<body.*?>(.*)<\/body.*/$1/is;
print &quot;$c\n&quot;;

LWP::Simple is pretty limited. If you want to pass args, take a look at LWP::UserAgent and the other parts of the LWP module. 'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
I know this is old, but just is case someone else runs into the problem, here is how to submit a form to a server using Perl (and HTTP & LWP modules).

This case submits a form variable named username and a form variable named password:

Code:
use strict;
use HTTP::Request::Common &quot;POST&quot;;
use LWP::UserAgent;

my $url=(&quot;[URL unfurl="true"]http://www.mywebsite.com/login.cgi&quot;);[/URL]
my $ua=LWP::UserAgent->new();

my $req=POST $url,[username=>'myname', password=>'mypassword'];

my $content=$ua->request($req)->as_string;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top