Symfony 2 redirect using POST(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 重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Symfony 2 使用 POST 重定向


- PHP - if 语句中的倒序 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01