Symfony 2 使用 POST 重定向

编程入门 行业动态 更新时间:2024-10-28 11:34:42
本文介绍了Symfony 2 使用 POST 重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在 Symfony 2 中,我的控制器中有以下代码:

In Symfony 2 I have the following code in my Controller:

// prepare to render the seller info panel $response = array( 'data' => $data, ); // render the seller info panel return $this->redirect($this->generateUrl('route', $response));

路线在哪里:

route: pattern: /listing/complete/{data} defaults: { _controller: FooBundle:Foo:action } requirements: _method: POST

这不起作用,因为重定向正在发出 GET 请求.我也试过这种模式,但它与路线不匹配:

This doesn't work since the redirect is making a GET request. I've also tried it this pattern, but its not matching the route:

route: pattern: /listing/complete defaults: { _controller: FooBundle:Foo:action } requirements: _method: POST

我发现路由文档没有帮助.有没有办法让重定向发出 POST 请求?路线会是什么样子,我是否必须在控制器中执行任何操作才能使其发生?

I've found the routing documentation unhelpful. Is there a way that I can have the redirect make a POST request? What would the route look like, and do I have to do anything in the controller to make it happen?

推荐答案

重定向 POST 请求是不可能的,因为浏览器必须重新发送 POST 数据(它不需要).在这种情况下,您应该做的是使用 转发.

It's impossible to redirect a POST request because the browser would have to re-send the POST data (which it doesn't). What you should do instead in this case is use forwarding.

更多推荐

Symfony 2 使用 POST 重定向

本文发布于:2023-10-10 22:57:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479999.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   Symfony   POST

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!