Georgio has asked for the wisdom of the Perl Monks concerning the following question:

Hi!

I need to redirect from my CGI-script to another site, posting some parameters to the other CGI-script. I did that using 'GET'-method:
...
    print redirect('http://www.newsite.com/new.cgi?param=someting&...');
... ,
But in this case the whole link including my parameters is being displayed in browser's address bar. I don't wish my parameters to be displayed in the address bar. For this reason I'd like to redirect using 'POST'- method.

How could I do that?

Thanks!

Replies are listed 'Best First'.
Re: POST and redirect
by sauoq (Abbot) on Sep 07, 2002 at 19:35 UTC

    You can't easily force a browser to POST data to another site.

    You might be able to work something out with JavaScript. I have no idea if it would work but you might be able to send back a form with the action and method appropriately set, all of the data you want to send stuck in hidden inputs, and then submit the form in the onLoad method. Personally, I'd avoid your site like the plague if you tried pulling those kinds of shenanigans but I might not be representative of your user base.

    A better idea would be to make the request on their behalf (using LWP::UserAgent, for instance) and then send the result back to the client.

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: POST and redirect
by spartacus9 (Beadle) on Sep 07, 2002 at 19:45 UTC
    I've fought this problem before and it turned out that the RFC does not allow for redirection to occur with anything but the GET or HEAD method. What I've done instead is to use LWP and the HTTP::Request method to do the POST and then give the result back to the user's browser. For instance:
    my $req = new HTTP::Request POST => 'http://www.somewhere.com'; $req->content_type('application/x-www-form-urlencoded'); $req->content($content); print $res->content;

    Hope this helps. I haven't found any cleaner solution.
Re: POST and redirect
by Kanji (Parson) on Sep 07, 2002 at 21:14 UTC

    davorg posted a similar question just a few days ago, so you might want to check out some of the responses that received in addition to whatever you see here.

        --k.