1. <i id='8tFx3'><tr id='8tFx3'><dt id='8tFx3'><q id='8tFx3'><span id='8tFx3'><b id='8tFx3'><form id='8tFx3'><ins id='8tFx3'></ins><ul id='8tFx3'></ul><sub id='8tFx3'></sub></form><legend id='8tFx3'></legend><bdo id='8tFx3'><pre id='8tFx3'><center id='8tFx3'></center></pre></bdo></b><th id='8tFx3'></th></span></q></dt></tr></i><div id='8tFx3'><tfoot id='8tFx3'></tfoot><dl id='8tFx3'><fieldset id='8tFx3'></fieldset></dl></div>
    <legend id='8tFx3'><style id='8tFx3'><dir id='8tFx3'><q id='8tFx3'></q></dir></style></legend>
  2. <tfoot id='8tFx3'></tfoot>

    <small id='8tFx3'></small><noframes id='8tFx3'>

      <bdo id='8tFx3'></bdo><ul id='8tFx3'></ul>

    1. HttpException:400 无法验证您提交的数据

      HttpException:400 Unable to verify your data submission(HttpException:400 无法验证您提交的数据)
      <i id='gR7Vi'><tr id='gR7Vi'><dt id='gR7Vi'><q id='gR7Vi'><span id='gR7Vi'><b id='gR7Vi'><form id='gR7Vi'><ins id='gR7Vi'></ins><ul id='gR7Vi'></ul><sub id='gR7Vi'></sub></form><legend id='gR7Vi'></legend><bdo id='gR7Vi'><pre id='gR7Vi'><center id='gR7Vi'></center></pre></bdo></b><th id='gR7Vi'></th></span></q></dt></tr></i><div id='gR7Vi'><tfoot id='gR7Vi'></tfoot><dl id='gR7Vi'><fieldset id='gR7Vi'></fieldset></dl></div>
      • <bdo id='gR7Vi'></bdo><ul id='gR7Vi'></ul>

                <tbody id='gR7Vi'></tbody>

            • <legend id='gR7Vi'><style id='gR7Vi'><dir id='gR7Vi'><q id='gR7Vi'></q></dir></style></legend>

              <small id='gR7Vi'></small><noframes id='gR7Vi'>

                <tfoot id='gR7Vi'></tfoot>
                本文介绍了HttpException:400 无法验证您提交的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我的日志文件充满了这些错误

                My log files are filled with these errors

                2021-11-19 12:39:42 [27.xxx.xxx.xxx][1958][gi96uqh6atadlbsg2ksjfltd9e][error][yiiwebHttpException:400] yiiwebBadRequestHttpException: Unable to verify your data submission. in /var/www/html/vendor/yiisoft/yii2/web/Controller.php:218
                

                似乎无法弄清楚原因.因为我也无法复制这个问题.

                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.

                在我的

                我有这个

                <meta name="csrf-param" content="_csrf-frontend">
                <meta name="csrf-token" content="oidpfJVSR28kMxgD4loRdgIs3TCRVITuR6Ly3Z587nLxdgIt-h8XIlFbSECzCEgHUmqaQ9InwaIYzJ2u-ySaIw==">
                

                并且因为我使用 $form = ActiveForm::begin([]),所以我的表单有这个隐藏字段

                and because i use $form = ActiveForm::begin([]), for my form there is this hidden field

                <form id="form-small" action="/frontend/web/search/" method="post">
                <input type="hidden" name="_csrf-frontend" value="oidpfJVSR28kMxgD4loRdgIs3TCRVITuR6Ly3Z587nLxdgIt-h8XIlFbSECzCEgHUmqaQ9InwaIYzJ2u-ySaIw==">
                

                这是我的 $form = ActiveForm::begin([])

                $form = ActiveForm::begin([
                        'id' => $model->formName().'-form-small',
                        'action' => ['/search/default/id'],
                        'method' => 'post',
                        'scrollToError' => false,
                        'validateOnChange' => false,
                        'validateOnSubmit' => true,
                        'enableClientValidation' => true,
                        'enableAjaxValidation' => true,
                        'fieldConfig' => [
                            'options' => [
                                'tag' => false,
                            ],
                        ],
                    ]);
                

                我的页脚中也有这个 JS.(main.php 布局)

                i also have this JS in my footer. (main.php layout)

                <script>
                    $.ajaxSetup({
                      headers: {
                        'X-CSRF-TOKEN': '<?= yii::$app->request->csrfToken ?>'
                      }
                    });
                </script>
                

                而且我也不想关闭 CSRF.

                And i DO NOT want to turn CSRF off either.

                在我的 main.php 我有这个

                 'request' => [
                            'csrfParam' => '_csrf-frontend',
                            'enableCsrfCookie' => false, 
                            'enableCookieValidation' => true,
                            'cookieValidationKey' => 'frontend-cookie-2021',
                        ],
                

                我编辑了yii/framework/.php

                并在 841

                echo ' -- start--';
                        echo '<br><br><br>';
                        print_r($trueToken); 
                        echo '<br><br><br>';
                print_r($this->getBodyParam($this->csrfParam));
                echo '<br><br><br>';
                print_r($this->getCsrfTokenFromHeader());
                echo '<br><br><br>'; 
                echo ' -- end--';
                die;
                

                每次我提交表单时.$trueToken 令牌似乎不同.即使我不刷新页面.

                every time i submit my form. the $trueToken token seems to be different. even when i don't refresh the page.

                如下图

                -- start--
                S-r869794GPYBi8voh-dXVDFLLWl8GvWhw6Qvn4c7icYu5e6sbCwLq1uf2zzTcQsAINrxuaDLprYYP_NG0Sadg==
                
                b4GMJgf6dmn8H64oljr6uxokFC2WbQeLP4bY_SI-7Pg80Od3aLcmJIl3_mvHaKPKSmJTXtUeQsdg6LeOR2aYqQ==
                
                b4GMJgf6dmn8H64oljr6uxokFC2WbQeLP4bY_SI-7Pg80Od3aLcmJIl3_mvHaKPKSmJTXtUeQsdg6LeOR2aYqQ==
                -- end--
                

                知道如何解决这个问题吗?谢谢.

                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

                获取已经生成的令牌

                $.ajaxSetup({
                  headers: {
                    'X-CSRF-Token': $('meta[name="_csrf-frontend"]').attr('content')
                  }
                });
                

                这篇关于HttpException:400 无法验证您提交的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Is Joomla 2.5 much faster than Joomla 1.5 Querywise(Joomla 2.5 比 Joomla 1.5 Querywise 快得多吗)
                How to share Joomla login session from one joomla website to one ASP.Net MVC website(如何将 Joomla 登录会话从一个 joomla 网站共享到一个 ASP.Net MVC 网站)
                htaccess redirect root to subdirectory but allow index.php in root AND query strings to function(htaccess 将根重定向到子目录,但允许根和查询字符串中的 index.php 起作用)
                Joomla include database functions(Joomla 包含数据库功能)
                nl2br() not working when displaying SQL results(显示 SQL 结果时 nl2br() 不起作用)
                Joomla 2.5 JFactory::getSession(); seems to be caching in firefox(Joomla 2.5 JFactory::getSession();似乎在 Firefox 中缓存)
                <tfoot id='e5W0Q'></tfoot>

                    <small id='e5W0Q'></small><noframes id='e5W0Q'>

                    <legend id='e5W0Q'><style id='e5W0Q'><dir id='e5W0Q'><q id='e5W0Q'></q></dir></style></legend>
                      <i id='e5W0Q'><tr id='e5W0Q'><dt id='e5W0Q'><q id='e5W0Q'><span id='e5W0Q'><b id='e5W0Q'><form id='e5W0Q'><ins id='e5W0Q'></ins><ul id='e5W0Q'></ul><sub id='e5W0Q'></sub></form><legend id='e5W0Q'></legend><bdo id='e5W0Q'><pre id='e5W0Q'><center id='e5W0Q'></center></pre></bdo></b><th id='e5W0Q'></th></span></q></dt></tr></i><div id='e5W0Q'><tfoot id='e5W0Q'></tfoot><dl id='e5W0Q'><fieldset id='e5W0Q'></fieldset></dl></div>
                          <tbody id='e5W0Q'></tbody>
                          <bdo id='e5W0Q'></bdo><ul id='e5W0Q'></ul>