HttpException:400 Unable to verify your data submission(HttpException:400 无法验证您提交的数据)
问题描述
我的日志文件充满了这些错误
My log files are filled with these errors
似乎无法弄清楚原因.因为我也无法复制这个问题.
Can't seem to figure out why. As i can't replicate the problem either.
我阅读此内容,但该解决方案不适用于我,因为我所有的表单都是使用 $form = ActiveForm::begin([])
创建的,而且我没有上传文件.
I've read this, but the solution doesn't apply to me as all my forms are created using $form = ActiveForm::begin([])
and i'm not uploading files.
在我的
并且因为我使用 $form = ActiveForm::begin([])
,所以我的表单有这个隐藏字段
and because i use $form = ActiveForm::begin([])
, for my form there is this hidden field
这是我的 $form = ActiveForm::begin([])
我的页脚中也有这个 JS.(main.php 布局)
i also have this JS in my footer. (main.php layout)
而且我也不想关闭 CSRF.
And i DO NOT want to turn CSRF off either.
在我的 main.php
我有这个
我编辑了yii/framework/.php
并在 841
每次我提交表单时.$trueToken
令牌似乎不同.即使我不刷新页面.
every time i submit my form. the $trueToken
token seems to be different. even when i don't refresh the page.
如下图
知道如何解决这个问题吗?谢谢.
Any idea how to fix this? Thank you.
推荐答案
一个 CSRF 令牌头名称是 X-CSRF-Token
A CSRF token header name is X-CSRF-Token
https://github.com/yiisoft/yii2/blob/552593ca3bcd9b4c9b19913e9e56de9548db59e3/framework/web/Request.php#L103
获取已经生成的令牌
这篇关于HttpException:400 无法验证您提交的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!