I'm trying to perform a redirect from one controller to another while passing along some parameters. Unfortunately the value of the parameters are long and obnoxious looking in the GET query string. Is there anyway I can use POST instead on the redi开发者_开发知识库rect to get a nicer looking URL?
Thanks.
As everyone said, you cannot redirect to post.
However, you can avoid ugly URLs by sticking your values in TempData
instead of the route.
You can't do a proper POST redirect, but you can use JavaScript in the browser to mimic a POST redirect:
<form id="myform" action="http://mywebsite.com/">
<input name="myparameter" value="12345" type="hidden" />
</form>
<script>
document.getElementById("myform").submit()
</script>
It's not a true redirect and it won't perform as well as a redirect, but this should work.
A "Redirect" is a GET. If you're doing a real direct what you're doing is essentially informing the browser to go to another url. The browser than makes another http call (using GET) to the new url. The url may contain parameters but it will always be a GET and not a POST.
What you could do is store some data in session and then when the second (redirected) request comes in, you can access these values from session.
Sorry, no. Redirects via POST
are simply not supported in the HTTP spec. Most clients implementing the common kinds of redirects (301 - Permanent and 302 - Temporary) issue a GET
request to the new location.
精彩评论