davorg has asked for the wisdom of the Perl Monks concerning the following question:
I'm having some problems with some LWP that I'd appreciate some help with. I'll describe the problem, my proposed solution and what's wrong with my solution.
The Problem
I'm collecting data from a form and passing it on to a third party CGI program. The data inputs on the form are determined by what is sensible to give the user. The data passed on to the CGI program is determined by the owners of the program.
These two sets of requirements are at odds with each other.
For example, I'm giving customers a choice of paying £x/month or £y/year. This is obviously going to be controlled by one input (either a select with two options or a pair of radio buttons). It makes no sense to have one input for "amount" and another for "period". Unfortunately this is exactly what the CGI program expects.
So my problem is that I need to send a different set of CGI parameters to the ones that are on the form.
My Solution
So I thought I'd write another CGI program that sits between the form and the third-party CGI program. My program would look at the incoming parameters, calculate any extra parameters needed (e.g. create an "amount" parameter based on the value in the "period" parameter), and then make a POST request to the external CGI program. It then need to display the results it gets back in the browser.
Here's roughly what I've got.
#!/usr/bin/perl -w use strict; use CGI ':standard'; use LWP; my $url = 'http://blah, blah, blah'; my $ua = LWP::UserAgent->new; $ua->cookie_jar( {} ); # Note: assumes no multivalued parameters my %param = map { $_ => param($_) } param; # removed code to munge %param my $resp = $ua->post($url, [ %param ]); print header; print $resp->content;
This pretty much does what I want, but there are a couple of problems.
The Problems
- The browser shows the URL of my progrma rather than the external CGI program.
- The relative URLs within the displayed content are all broken as the browser is interpreting them as relative to my program.
It seems to me that what I really want is a "redirect", but you can't redirect a POST request (or can you?)
Are there any other suggestions? Am I missing something obvious?
--<http://www.dave.org.uk>
"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: LWP Redirection Problem
by Kanji (Parson) on Sep 02, 2002 at 10:52 UTC | |
by davorg (Chancellor) on Sep 02, 2002 at 11:06 UTC | |
Re: LWP Redirection Problem
by Arien (Pilgrim) on Sep 02, 2002 at 11:02 UTC | |
Re: LWP Redirection Problem
by thpfft (Chaplain) on Sep 02, 2002 at 11:27 UTC | |
Re: LWP Redirection Problem
by fruiture (Curate) on Sep 02, 2002 at 10:49 UTC | |
Re: LWP Redirection Problem
by arhuman (Vicar) on Sep 02, 2002 at 20:49 UTC | |
Re: LWP Redirection Problem
by zaimoni (Beadle) on Sep 03, 2002 at 03:04 UTC | |
by Aristotle (Chancellor) on Sep 03, 2002 at 13:15 UTC | |
by zaimoni (Beadle) on Sep 03, 2002 at 22:34 UTC | |
by Georgio (Sexton) on Sep 08, 2002 at 18:23 UTC | |
by Aristotle (Chancellor) on Sep 09, 2002 at 12:10 UTC | |
by zaimoni (Beadle) on Sep 11, 2002 at 22:06 UTC |