BaseEncrypter.php 第 45 行中的 Laravel 5.1 DecryptException:有效负载无效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33255002/
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 12:33:11  来源:igfitidea点击:

Laravel 5.1 DecryptException in BaseEncrypter.php line 45: The payload is invalid

phplaravellaravel-5laravel-5.1

提问by geoffs3310

I have a L5.1 app that uses jquery datatables with ajax datasources. All of them work fine apart from one that causes the server to throw an exception when it posts the ajax request to get the data. The error I'm getting is:

我有一个 L5.1 应用程序,它使用带有 ajax 数据源的 jquery 数据表。除了导致服务器在发布 ajax 请求以获取数据时抛出异常之外,所有这些都可以正常工作。我得到的错误是:

DecryptException in BaseEncrypter.php line 45:
The payload is invalid.

I think this possibly has something to do with how much data the ajax request is posting since this particular datatable posts more data than the others. Also it must have something to do with CSRF protection because if I exclude the route from CSRF then it works fine.

我认为这可能与 ajax 请求发布的数据量有关,因为这个特定的数据表发布的数据比其他数据表多。此外,它必须与 CSRF 保护有关,因为如果我从 CSRF 中排除路由,则它可以正常工作。

Here are the headers I'm sending through:

这是我发送的标题:

Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Content-Length:1589
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:gsScrollPos=; _gat=1; _ga=GA1.2.478522745.1445258590; XSRF-TOKEN=eyJpdiI6IlVYckJ5RW5rcVFVUlU0RjJLYjNmOWc9PSIsInZhbHVlIjtheitroadzRPcG4wWEhsaHVsSGdFRzh0UnhWWU5kXC9Jd0F1YWNjK0poOW5TcVpWMHhSZ0l6MXNtWVdZZ1pJVHBrRUJpYkZuaENacUxsM2M4RkxKOGVoNG5BSGtnPT0iLCJtYWMiOiJkNGUxOWM0NzQ2MThjNDg1OTg0MjIwYmY5NGNmZGEzNzc5ZjZiNmExYTQ1Yjk0YTc2YWRlMTYyZDI5OWQ5N2ZkIn0%3D; session=eyJpdiI6ImdpRXozUXBmT2lLRmhOSnU0QW9zTlE9PSIsInZhbHVlIjoiMmN3QXZWeVFqWEhMSmw1QTdIaEY4WU1EOEszM1RKQU0xTE00Z2I5VVh3RjNLSFpqQUZ6dDRYdU0rK3FVekhZXC9rZkNWakN4a0ZtOTMrYnZDS0doWHF3PT0iLCJtYWMiOiI0MDA3ZDgyNTI3MTY0ZDlmNjZjM2IzYmJjZTQ2NTc4ZjdiNDRjN2M4M2VhMWU1MDc2YzE1ZmM1MDA1M2NkNDZlIn0%3D
Host:local.thecraftchannel.tv
Origin:https://local.website.com
Pragma:no-cache
Referer:https://local.website.com/admin/shows/edit/1
User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36
X-Requested-With:XMLHttpRequest
X-XSRF-TOKEN:PGBwTUHVjIQJPuZHLhqX2yEJFl0srgP1J4lO2oJy

Here is the form data that is being sent through also with the request:

这是通过请求发送的表单数据:

draw:1
columns[0][data]:0
columns[0][name]:
columns[0][searchable]:true
columns[0][orderable]:true
columns[0][search][value]:
columns[0][search][regex]:false
columns[1][data]:1
columns[1][name]:
columns[1][searchable]:true
columns[1][orderable]:true
columns[1][search][value]:
columns[1][search][regex]:false
columns[2][data]:2
columns[2][name]:
columns[2][searchable]:true
columns[2][orderable]:true
columns[2][search][value]:
columns[2][search][regex]:false
columns[3][data]:3
columns[3][name]:
columns[3][searchable]:true
columns[3][orderable]:true
columns[3][search][value]:
columns[3][search][regex]:false
columns[4][data]:4
columns[4][name]:
columns[4][searchable]:true
columns[4][orderable]:true
columns[4][search][value]:
columns[4][search][regex]:false
columns[5][data]:5
columns[5][name]:
columns[5][searchable]:false
columns[5][orderable]:false
columns[5][search][value]:
columns[5][search][regex]:false
order[0][column]:0
order[0][dir]:asc
start:0
length:10
search[value]:
search[regex]:false
product_ids[]:8
product_ids[]:5
product_ids[]:4
product_ids[]:3
product_ids[]:6
product_ids[]:9
product_ids[]:14
product_ids[]:11
product_ids[]:16
product_ids[]:21
product_ids[]:23

Anyone know why I am getting this error?

任何人都知道为什么我会收到此错误?

回答by Tim

If you want to use the CSRF protection provided by Laravel, you have to specify the CSRF token in your requests.

如果你想使用 Laravel 提供的 CSRF 保护,你必须在你的请求中指定 CSRF 令牌。

To do this, you could do the following:

为此,您可以执行以下操作:

Add a meta tag like this:

添加一个像这样的元标记:

<meta name="csrf-token" content="{{ csrf_token() }}">

And setup your jQuery to use this token for all ajax requests like this:

并设置您的 jQuery 以将此令牌用于所有 ajax 请求,如下所示:

$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});

Original answer

原答案

Since you have a lot of data maybe the column type in your database is too small and you are therefore getting this error.

由于您有大量数据,因此数据库中的列类型可能太小,因此您会收到此错误。

Try to set the column to longtextinstead of textin your migration and see if that works.

尝试将列设置为longtext而不是text在您的迁移中,看看是否有效。