Link to home
Start Free TrialLog in
Avatar of serg111
serg111

asked on

How to redirect with POST request

To redirect with GET request I use header Location: http...
but how can I redirect POST request?
Avatar of Sapa
Sapa

You cannot redirect POST to another POST. The POST request can be only the first one in the chain of redirects. But you can pass all POST'ed parameters in URL, if the list is not too big, has no uploads and, of course, the script where you redirect to allows GET method.

Another trick is using Javascript and auto-submited form instead of simple redirect. For example, POST to url1.cgi
will produce such HTML output:

<html>
<body onLoad="document.form1.submit()">
<form name="form1" action="url2.cgi" method="POST">
<input type="hidden" name="param1" value="value1">
<input type="hidden" name="param2" value="value2">
...
<input type="hidden" name="paramN" value="valueN">
</form>
</body>
</html>

- Sapa
Avatar of serg111

ASKER

The script doesn't allow GET method, POST only :-(

And I want just to redirect , not use intermediate page with Javascript.
RFC-2616 ("Hypertext Transfer Protocol -- HTTP/1.1")
Chapter 10.3 ("Redirection 3xx"), page 61

"This class of status code indicates that further action needs to be taken by the user agent in order to fulfill the request.  The action required MAY be carried out by the user agent without interaction with the user if and only if the method used in the second request is GET or HEAD. A client SHOULD detect infinite redirection loops, since such loops generate network traffic for each redirection."

Chapter 10.3.2 ("301 Moved Permanently"), page 62

"If the 301 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change the conditions under which the request was issued.

Note: When automatically redirecting a POST request after receiving a 301 status code, some existing HTTP/1.0 user agents will erroneously change it into a GET request."

Chapter 10.3.3 ("302 Found"), page 63
"If the 302 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change the conditions under which the request was issued.

Note: RFC 1945 and RFC 2068 specify that the client is not allowed to change the method on the redirected request.  However, most existing user agent implementations treat 302 as if it were a 303 response, performing a GET on the Location field-value regardless of the original request method. The status codes 303 and 307 have been added for servers that wish to make unambiguously clear which kind of reaction is expected of the client."

Chapter 10.3.8 ("307 Temporary Redirect"), page 65
"If the 307 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change the conditions under which the request was issued."

Full text of RFC-2616 you can read there: http://rfc.net/rfc2616.html

So, HTTP/1.1 standard allows POST-to-POST redirecttion,
but _with_user_confirmation_only! Really, MSIE, NN and AOL browsers are "some existing HTTP/1.0 user agents" which "will erroneously change it into a GET request".

Sorry for ruining your bright hopes.

- Sapa


Avatar of serg111

ASKER

Sapa,

please, change answer to comments.
If noone can answer this question I would accept your comments
ASKER CERTIFIED SOLUTION
Avatar of Sapa
Sapa

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you can usen an HTTP 307 to redirect an post request.
Look at www.pda-systems.com thy have an tutorial wich shows this