首页 > 解决方案 > Symfony 更新 4.3 到 4.4 不支持内容类型

问题描述

我已将 Symfony 项目(api 平台)从 4.3 更新到 4.4,但现在我在一些 POST/PUT 请求中收到此错误:

状态码:415 不支持的媒体类型

不支持内容类型“application/json”。支持的 MIME 类型是“”。

追踪哪里坏了:

../vendor/api-platform/core/src/EventListener/DeserializeListener.php

使用命令:

php bin/控制台调试:配置 api_platform

api_platform:
    path_segment_name_generator: api_platform.path_segment_name_generator.dash
    enable_fos_user: true
    eager_loading:
        force_eager: false
        enabled: true
        fetch_partial: false
        max_joins: 30
    http_cache:
        max_age: 0
        shared_max_age: 3600
        vary:
            - Content-Type
            - Authorization
            - Origin
        public: true
        etag: true
        invalidation:
            enabled: false
            varnish_urls: {  }
            request_options: {  }
    oauth:
        enabled: true
        flow: password
        tokenUrl: /api/login
        clientId: ''
        clientSecret: ''
        type: oauth2
        authorizationUrl: /oauth/v2/auth
        scopes: {  }
    mapping:
        paths:
            - /var/www/x/config/packages/apiplatform/user.yml
            - /var/www/x/config/packages/apiplatform/business.yml
            - /var/www/x/config/packages/apiplatform/service.yml
            - /var/www/x/config/packages/apiplatform/customers.yml
            - /var/www/x/config/packages/apiplatform/worker.yml
            - /var/www/x/src/Entity
    title: ''
    description: ''
    version: 0.0.0
    show_webby: true
    default_operation_path_resolver: api_platform.operation_path_resolver.unders                                                  core
    name_converter: null
    allow_plain_identifiers: false
    validator:
        serialize_payload_fields: {  }
    enable_nelmio_api_doc: false
    enable_swagger: true
    enable_swagger_ui: true
    enable_re_doc: true
    enable_entrypoint: true
    enable_docs: true
    enable_profiler: true
    collection:
        exists_parameter_name: exists
        order: ASC
        order_parameter_name: order
        pagination:
            enabled: true
            partial: false
            client_enabled: false
            client_items_per_page: false
            client_partial: false
            items_per_page: 30
            maximum_items_per_page: null
            page_parameter_name: page
            enabled_parameter_name: pagination
            items_per_page_parameter_name: itemsPerPage
            partial_parameter_name: partial
    resource_class_directories: {  }
    doctrine:
        enabled: true
    doctrine_mongodb_odm:
        enabled: false
    graphql:
        enabled: false
        default_ide: graphiql
        graphiql:
            enabled: false
        graphql_playground:
            enabled: false
        nesting_separator: _
        collection:
            pagination:
                enabled: true
    swagger:
        versions:
            - 2
            - 3
        api_keys: {  }
    mercure:
        enabled: false
        hub_url: null
    messenger:
        enabled: false
    elasticsearch:
        enabled: false
        hosts: {  }
        mapping: {  }
    exception_to_status:
        Symfony\Component\Serializer\Exception\ExceptionInterface: 400
        ApiPlatform\Core\Exception\InvalidArgumentException: 400
        ApiPlatform\Core\Exception\FilterValidationException: 400
        Doctrine\ORM\OptimisticLockException: 409
    formats:
        jsonld:
            mime_types:
                - application/ld+json
        json:
            mime_types:
                - application/json
        html:
            mime_types:
                - text/html
    patch_formats: {  }
    error_formats:
        jsonproblem:
            mime_types:
                - application/problem+json
        jsonld:
            mime_types:
                - application/ld+json

标签: symfonysymfony4api-platform.com

解决方案


推荐阅读