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 无法验证您提交的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                <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>