如何解决 Laravel “Payload is invalid” ?

huangapple go评论75阅读模式
英文:

How to solve Laravel "Payload is invalid"?

问题

我在生产模式下的Laravel应用程序中遇到了一个严重问题...

我不知道它何时触发,但这个网站每天有大约10,000名访问者,而我的Laravel日志文件现在非常大...

在这里,你可以找到日志:

负载无效。 {"exception":“[object](Illuminate \\ Contracts \\ Encryption \\ DecryptException(code:0):负载无效。位于/home/web/abuk/vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:195)
[stacktrace]
#0 /home/web/abuk/vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php(136): Illuminate\\Encryption\\Encrypter->getJsonPayload(NULL)
#1 /home/web/abuk/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(154): Illuminate\\Encryption\\Encrypter->decrypt('eyJpdiI6Ik1wN0p... ',false)
#2 /home/web/abuk/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(136): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->getTokenFromRequest(Object(Illuminate\\Http\\Request))
#3 /home/web/abuk/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(74): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->tokensMatch(Object(Illuminate\\Http\\Request))
#4 /home/web/abuk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#5 /home/web/abuk/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#6 /home/web/abuk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#7 /home/web/abuk/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(56): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#8 /home/web/abuk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\\Session\\Middleware\\StartSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))

我真的不知道它是从哪里来的...

英文:

I have a big problem with my laravel application on production mode only...

I don't know when it's firing, but this website is around 10k visitors/day and my laravel log file is so big now..

Here you can find the log :

The payload is invalid. {"exception":"[object] (Illuminate\\Contracts\\Encryption\\DecryptException(code: 0): The payload is invalid. at /home/web/abuk/vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:195)
[stacktrace]
#0 /home/web/abuk/vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php(136): Illuminate\\Encryption\\Encrypter->getJsonPayload(NULL)
#1 /home/web/abuk/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(154): Illuminate\\Encryption\\Encrypter->decrypt('eyJpdiI6Ik1wN0p...', false)
#2 /home/web/abuk/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(136): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->getTokenFromRequest(Object(Illuminate\\Http\\Request))
#3 /home/web/abuk/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(74): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->tokensMatch(Object(Illuminate\\Http\\Request))
#4 /home/web/abuk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#5 /home/web/abuk/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#6 /home/web/abuk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#7 /home/web/abuk/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(56): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#8 /home/web/abuk/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\\Session\\Middleware\\StartSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))

I really don't know from where it comes..

答案1

得分: 1

尝试使用以下命令清除缓存:

php artisan cache:clear

不要忘记在你的表单中包含 csrf
https://laravel.com/docs/6.x/csrf

英文:

Try to clear the cache with the following command:

php artisan cache:clear

Dont forget to include the csrf in your forms
https://laravel.com/docs/6.x/csrf

答案2

得分: 0

1- 执行命令:php artisan clear
2- 确保你的应用程序已生成了APP_KEY,如果没有,请运行命令:php artisan key:generate
3- 如果你正在使用 Jwt,请确保已生成JWT_SECRET,如果没有,请运行命令:php artisan jwt:secret

英文:

Please try this:
1- php artisan clear; or
2- make sure you application generated APP_KEY, if not do php artisan key: generate
3- if you are using Jwt make sure JWT_SECRET was generated, if not do php artisan jwt:secret

答案3

得分: 0

也许你忘记了表单中的 _token
@csrf

英文:

May be you frogot _token in the form
@csrf

huangapple
  • 本文由 发表于 2020年1月3日 19:28:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/59577818.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定