当我在PUT
生成的休息路线上使用DELETE
或FOSRestBundle
次请求时,会返回
禁止
您无权访问 此服务器上的/app_dev.php/api/resources/3。另外,一个 尝试使用时遇到403 Forbidden错误 ErrorDocument来处理请求。
当我使用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);
}
仅在我使用403
或putResourceAction
时才会抛出deleteResourceAction
。
感谢您的帮助!
答案 0 :(得分:0)
如果有人遇到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>
以其他方式描述here以仅允许指定的方法
RewriteCond %{REQUEST_METHOD} !^(DELETE|GET|HEAD|OPTIONS|POST|PROPFIND|PUT) [NC]
RewriteRule .* - [F,L]
答案 1 :(得分:-1)