如何使用 POST 动词重定向到页面?

问题描述:

当您在控制器中调用 RedirectToAction 时,它会使用 HTTP GET 自动重定向.我如何明确告诉它使用 HTTP POST?

When you call RedirectToAction within a controller, it automatically redirects using an HTTP GET. How do I explicitly tell it to use an HTTP POST?

我有一个接受 GET 和 POST 请求的操作,我希望能够使用 POST RedirectToAction 并向其发送一些值.

I have an action that accepts both GET and POST requests, and I want to be able to RedirectToAction using POST and send it some values.

像这样:

this.RedirectToAction(
    "actionname",
    new RouteValueDictionary(new { someValue = 2, anotherValue = "text" })
);

我希望使用 HTTP POST 而不是 GET 发送 someValueanotherValue 值.有人知道怎么做吗?

I want the someValue and anotherValue values to be sent using an HTTP POST instead of a GET. Does anyone know how to do this?

HTTP 不支持使用 POST 重定向到页面.当你重定向到某个地方时,HTTPLocation"标头告诉浏览器去哪里,然后浏览器为那个页面发出一个 GET 请求.您可能只需要为您的页面编写代码来接受 GET 请求和 POST 请求.

HTTP doesn't support redirection to a page using POST. When you redirect somewhere, the HTTP "Location" header tells the browser where to go, and the browser makes a GET request for that page. You'll probably have to just write the code for your page to accept GET requests as well as POST requests.