首页 > 解决方案 > Symfony FOS 休息包没有从 API url 获取我的 json 数据

问题描述

我正在尝试调用此 api:http://localhost/api/columns {"tab":"client"}

但我无法从 json 格式中得到那个值

我从浏览器收到此错误:{"code":404,"message":"No route found for \"GET \/api\/columns%20%7B%22tab%22:%22client%22%7D\""}

来自 CURL 的内容:{"code":400,"message":"Parameter \"tab\" of value \"NULL\" violated a constraint \"This value should not be null.\""}

这是我的 fos_rest.yml 文件:

fos_rest:
routing_loader: false
body_listener: true
exception:
  enabled: true
param_fetcher_listener: force
view:
  view_response_listener: 'force'
  formats:
    json: true
format_listener:
  rules:
    - { path: '^/api', prefer_extension: false , priorities: [json], fallback_format: json}

路线.yml

dashboard:
  type: rest
  resource: App\Controller\DashboardController
  prefix : api

我从中得到什么:php bin/console debug:router检查我的路线:

get_columns                GET      ANY      ANY    /api/columns.{_format}

标签: jsonsymfonyroutesfosrestbundle

解决方案


推荐阅读