Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-25 06:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found