如何使用 POST 动词重定向到页面? [英] How do you redirect to a page using the POST verb?

查看:35
本文介绍了如何使用 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.

这篇关于如何使用 POST 动词重定向到页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆