Solved

How to redirect with POST request

Posted on 2001-06-19
6
563 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Author Comment

by:serg111
Comment Utility
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
Comment Utility
Let it be comment... although it was an answer.

- Sapa
0
 
LVL 4

Expert Comment

by:Oliver_Dornauf
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now