Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

POST redirect

by ColonelPanic (Friar)
on Aug 24, 2001 at 23:32 UTC ( [id://107673]=perlquestion: print w/replies, xml ) Need Help??

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

I know this issue has been covered a lot before, but I couldn't find any post that answered my question exactly.

I have a form that calls a cgi, but I have another script that needs to do some processing of the data before the final cgi is called. Through searching, I was able to find this, posted by Merlyn:

use LWP::UserAgent; use HTTP::Request::Common; use CGI; use strict; my $agent = LWP::UserAgent->new; my $data = $agent->request(POST 'www.somewhere.com', [%original_CGI_Pa +rams]); #then print the data with CGI
Unfortunately, I can't use this approach, because the final CGI needs a cookie set on the client side. So, I would like to make something like this work:

print $cgi_query->redirect(POST 'www.somewhere.com', [%params]);
But, this doesn't work. Is there any way I can have the browser redierct to a POST like this?

Thanks,
ColonelPanic

When's the last time you used duct tape on a duct? --Larry Wall

Replies are listed 'Best First'.
Re: POST redirect
by blakem (Monsignor) on Aug 25, 2001 at 00:03 UTC
    This is a tricky subject, but basically redirecting a POST is a bad idea.... This article will walk you through all the issues.

    -Blake

      Arggh! I was worried that if I didn't find an answer, there might not be one. Thanks anyway.

      When's the last time you used duct tape on a duct? --Larry Wall
Re: POST redirect
by shotgunefx (Parson) on Aug 25, 2001 at 01:03 UTC
    If you don't mind that the data will get appeneded to the query string (and show up in the servers/proxy access logs), you could have the first script take it's parameters and url encode them and append them to the URL to redirect to (a GET) the third server (If it will accept GET requests.) If there is a lot of data or any multi_part data, this will not work.

    -Lee

    "To be civilized is to deny one's nature."
Re: POST redirect
by LiTinOveWeedle (Scribe) on May 23, 2002 at 11:33 UTC
    Hi man,
    redirect after post is litle bit dirty, and its not allowed in default in UserAgent.pm. But you can push things litle bit.

    Find this part in UserAgent.pm and edit like this:

    sub redirect_ok { # draft-ietf-http-v10-spec-02.ps from www.ics.uci.edu, specify: # # If the 30[12] status code is received in response to a request using # the POST method, the user agent must not automatically redirect the # request unless it can be confirmed by the user, since this might cha +nge # the conditions under which the request was issued. my($self, $request) = @_; # return 0 if $request->method eq "POST"; 1; }

    It should work now. Enjoy

    Edited:
    rob_au Gave me notice, that same can be easily done within script, just by redefining redirect_ok sub. Here is example:

    sub LWP::UserAgent::redirect_ok { 1 }

    Thanks

    Li Tin O've Weedle
    mad Tsort's philosopher

Re: POST redirect
by synapse0 (Pilgrim) on Aug 25, 2001 at 16:14 UTC
    Well, if you can live w/out the redirect (i.e. all the scripts live in the same place) then you can try using $cgi->save(FILE) to save the data to disk, then exec() the final script and read the saved file in when creating the new CGI object. As long as nothing was output by the first script, you should be able to work with the cookies ok. I've done similar things, but nothing exactly like this. So it should work, but it may not.. more info never hurts tho.
    G'luck
    -Syn0

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://107673]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-25 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found