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

  1. The browser shows the URL of my progrma rather than the external CGI program.
  2. 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


In reply to LWP Redirection Problem by davorg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.