首页 > 解决方案 > 请求的媒体类型无效

问题描述

在生产中运行的 Symfony 3.4 上,我不断收到此错误:

An Error Occurred! Uncaught PHP Exception Negotiation\Exception\InvalidMediaType: "" 
at /var/www/mywebsite/vendor/willdurand/negotiation/src/Negotiation/Accept.php line 24

我几乎无法调查该请求,因为它在构建它时失败了。

完整的跟踪是:

"file": "/var/www/mywebsite/vendor/willdurand/negotiation/src/Negotiation/Accept.php:24",
    "trace": [
        "/var/www/mywebsite/vendor/friendsofsymfony/rest-bundle/Negotiation/FormatNegotiator.php:105",
        "/var/www/mywebsite/vendor/friendsofsymfony/rest-bundle/EventListener/FormatListener.php:60",
        "/var/www/mywebsite/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:212",
        "/var/www/mywebsite/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:44",
        "/var/www/mywebsite/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:127",
        "/var/www/mywebsite/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:68",
        "/var/www/mywebsite/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:200",
        "/var/www/mywebsite/web/app.php:17"
    ]

周围的代码如下所示:

    public function __construct($value)
    {
        parent::__construct($value);

        if ($this->type === '*') {
            $this->type = '*/*';
        }

        $parts = explode('/', $this->type);

        if (count($parts) !== 2 || !$parts[0] || !$parts[1]) {
            throw new InvalidMediaType();
        }

当我记录的值时$this->type$value我发现它们都等于""(空字符串)。

当我尝试在该/var/www/mywebsite/web/app.php:17级别捕获此异常时,我一直遇到此错误...

我真的不知道谁能经常用这个无效的标题调用我的网站,以及如何摆脱这个污染错误日志。

任何想法?

标签: phpsymfonysymfony-3.4

解决方案


推荐阅读