Solved

How to redirect with POST request

Posted on 2001-06-19
6
588 Views
Last Modified: 2008-03-10
To redirect with GET request I use header Location: http...
but how can I redirect POST request?
0
Comment
Question by:serg111
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:Sapa
ID: 6208857
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
0
 
LVL 2

Author Comment

by:serg111
ID: 6208906
The script doesn't allow GET method, POST only :-(

And I want just to redirect , not use intermediate page with Javascript.
0
 
LVL 5

Expert Comment

by:Sapa
ID: 6209878
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


0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 2

Author Comment

by:serg111
ID: 6215200
Sapa,

please, change answer to comments.
If noone can answer this question I would accept your comments
0
 
LVL 5

Accepted Solution

by:
Sapa earned 100 total points
ID: 6215351
Let it be comment... although it was an answer.

- Sapa
0
 
LVL 4

Expert Comment

by:Oliver_Dornauf
ID: 7759669
you can usen an HTTP 307 to redirect an post request.
Look at www.pda-systems.com thy have an tutorial wich shows this
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question