2014-03-31 156 views
1

我跟着这个link 当我运行此命令,看看Get方法是否工作得很好我的终端上显示此错误错误415:不支持的媒体类型。415不支持的媒体类型

我要见我的源代码:

1 - 首先我把我的配置文件:

#应用程序/配置/ config.yml sensio_framework_extra: 观点: 注释:假

fos_rest:

param_fetcher_listener: true 
body_listener: true 
format_listener: true 
view: 
    view_response_listener: 'force' 

2-后,我刚修好我的路由文件:

#应用程序/配置/ routing.yml中

minn_ads_api: 
    resource: "@MinnAdsAPIBundle/Resources/config/routing.yml" 
    type: rest 

3-我还设置路由文件在我的* AdsAPIBundle *

#AdsAPIBundle/Resources/config/routing.yml 
brend: 
    type: rest 
    resource: Minn\AdsAPIBundle\Controller\BrendController 

4-在我AdsAPIBundle我只需插入功能:

#src/BundleApi/Controller/BrendController.php 
    /** 
    * @Rest\View 
    * @Rest\Get("/api/brend/{id}", requirements={"id" = "\d+"}, defaults={"id" = 1}) 
    */ 
    public function getAction($id) { 
     $repo = $this->getDoctrine()-> 
       getManager()-> 
       getRepository("MinnAdsBundle:Brend"); 
     $brend = $repo->find($id); 

     return array('brend' => $brend); 
    } 

回答

6

也许你需要添加一个默认格式:

# app/config/config.yml 
fos_rest: 
    routing_loader: 
     default_format: json 
+1

实体被发现,并我们返回200 OK! > ** HTTP/1.1 200 OK ** – IsmailJallouli

+1

您在响应头中看到了什么内容类型?你在客户端支持这个吗? – Dunken

相关问题