[英]Symfony2 FOSRestBundle PUT Action FORM returns empty results
[英]How to handle PUT/DELETE requests in Symfony2 FOSRestBundle
當我在FOSRestBundle
生成的其余路由上使用PUT
或DELETE
請求時,它返回
禁止的
您無權訪問此服務器上的/app_dev.php/api/resources/3。 此外,在嘗試使用ErrorDocument處理請求時遇到403禁止錯誤。
當我使用GET
或POST
它就可以正常工作!
這是我的其余配置:
fos_rest:
format_listener:
rules:
- { prefer_extension: false, priorities: ['json','xml','html'], fallback_format: json }
view:
view_response_listener: true
formats:
xml: true
json: true
templating_formats:
html: true
mime_types:
json: ['application/json', 'application/x-json']
routing_loader:
default_format: json
include_format: false
body_listener: true
我的休息控制器:
/**
* @Rest\View
*/
public function putResourceAction(Request $request, $id)
{
return array(1, 2, 3);
}
僅當我使用putResourceAction
或deleteResourceAction
時,它將引發403
。
謝謝你的幫助!
如果有人遇到PUT,DELETE或其他方法不可用的此類問題,請嘗試將其添加到.htaccess中:
<RequireAny>
Require method DELETE GET POST PUT OPTIONS
</RequireAny>
<Limit GET POST PUT DELETE HEAD OPTIONS>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST PUT DELETE HEAD OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
此處描述的其他方式僅允許指定的方法
RewriteCond %{REQUEST_METHOD} !^(DELETE|GET|HEAD|OPTIONS|POST|PROPFIND|PUT) [NC]
RewriteRule .* - [F,L]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.