2016-07-15 31 views
0

當我用剩下的路線PUTDELETE請求由FOSRestBundle生成,它返回如何處理Symfony2的FOSRestBundle PUT/DELETE請求

故宮

您沒有權限訪問 /這個服務器上的app_dev.php/api/resources/3。此外,嘗試使用 ErrorDocument來處理請求時遇到了禁止的錯誤。

當我使用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); 
} 

它拋出403只有當我使用putResourceActiondeleteResourceAction

感謝您的幫助!

+0

不會當你用註釋'@method( 「PUT」)'行動工作? – Gordon

+0

@戈登號它給出同樣的錯誤。即使不使用'@Method(「PUT」)''debug:router'表示接受的方法是'PUT'。有什麼與文件權限以任何方式? – Mehulkumar

+0

你可以檢查你的web服務器是否允許PUT請求。請參閱http://serverfault.com/questions/438183/how-to-enable-all-http-methods-in-an-apache-http-server或https://bjornjohansen.no/restrict-allowed-http-methods -in-nginx – Gordon

回答