簡體   English   中英

如何在Symfony2 FOSRestBundle中處理PUT / DELETE請求

[英]How to handle PUT/DELETE requests in Symfony2 FOSRestBundle

當我在FOSRestBundle生成的其余路由上使用PUTDELETE請求時,它返回

禁止的

您無權訪問此服務器上的/app_dev.php/api/resources/3。 此外,在嘗試使用ErrorDocument處理請求時遇到403禁止錯誤。

當我使用GETPOST它就可以正常工作!

這是我的其余配置:

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);
}

僅當我使用putResourceActiondeleteResourceAction時,它將引發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]

請檢查您的Web服務器配置中允許的方法。

apache的信息

對於Nginx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM