Laravel:有效载荷无效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44590801/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 16:09:17  来源:igfitidea点击:

Laravel : The payload is invalid

laravelexceptionencryptionlaravel-5.4

提问by Fran?ois

I've upgraded 2 laravel applications on 5.4 few months ago.

几个月前,我在 5.4 上升级了 2 个 Laravel 应用程序。

Those application were created on 5.1, and I've always follow the upgrade guide 1 month after any release publication.

这些应用程序是在 5.1 上创建的,我总是在发布任何版本后 1 个月遵循升级指南。

Since 5.4, I often have this kind of error on POST request :

从 5.4 开始,我经常在 POST 请求中出现这种错误:

Illuminate\Contracts\Encryption\DecryptException·The payload is invalid


app/Http/Middleware/CheckForMaintenanceMode.php:43App\Http\Middleware\CheckForMaintenanceMode::handle   
         throw new HttpException(503);
    }
    return $next($request); //line 43
}}

Most of the time POST request are ok, but sometimes (around 1 POST request on 1000) I have this error. I fail to reproduce it.

大多数情况下 POST 请求都可以,但有时(大约 1000 个 POST 请求)我有这个错误。我无法重现它。

Thanks

谢谢

回答by Hemerson Varela

Make sure that the column that you are using to store the encrypted is long enough.

确保用于存储加密的列足够长。

I got this same exception because my 64 encoded string was being strip down due to column length.

我遇到了同样的异常,因为我的 64 编码字符串由于列长度而被剥离。

take in account that the size of the encrypted string can change depending on the size of the text passed through the encrypt function.

考虑到加密字符串的大小可能会根据通过 encrypt 函数的文本大小而变化。

回答by Hemerson Varela

You need to be using the EncryptCookiesmiddleware for the route your're accessing. Do you have the 'web' middleware group applied to your routes?

您需要将EncryptCookies中间件用于您正在访问的路由。您是否将“网络”中间件组应用于您的路线?

Your Http Kernel should have this in it:

您的 Http 内核中应该包含以下内容:

protected $middlewareGroups = [
    'web' => [
        \App\Http\Middleware\EncryptCookies::class,
        \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        \App\Http\Middleware\VerifyCsrfToken::class,
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
        \Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,
    ],

    'api' => [
        'bindings',
    ],

];

Then you can apply 'web' to your routes/groups.

然后您可以将“网络”应用于您的路线/组。