【问题标题】:415 Unsupported Media Type415 不支持的媒体类型
【发布时间】:2014-05-10 21:57:39
【问题描述】:

我关注了这个link 当我运行此命令以查看 Get 方法是否正常工作时,我的终端中显示此错误 ERROR 415: Unsupported Media Type.

我要去看看我的源代码:

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

#app/config/config.yml sensio_framework_extra: 看法: 注释:假

fos_rest:

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

2- 在我修复路由文件之后:

#app/config/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);
    }

【问题讨论】:

    标签: symfony fosrestbundle


    【解决方案1】:

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

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

    【讨论】:

    • 实体被找到,我们返回 200 OK !! > HTTP/1.1 200 正常
    • 您在响应标头中看到了什么 Content-Type?你在客户端支持这个吗?
    猜你喜欢
    • 2019-05-01
    • 2017-06-30
    • 2017-07-05
    • 2016-11-26
    • 2015-08-21
    • 2015-08-29
    相关资源
    最近更新 更多