【问题标题】:Laravel post - 419 unknown statusLaravel 发布 - 419 未知状态
【发布时间】:2019-10-22 04:35:26
【问题描述】:

我正在尝试使用this package,它可以满足我的所有需求。因此,除了我上传图片时,一切似乎都正常。 它根本不会用到 UtilsController@uploadfile 函数。

Route::post('/uploadfile', 'UtilsController@uploadfile');



public function uploadfile(Request $request){
        $img = $request->img;
        $newlocation = $request->newlocation;
        $filename = $request->filename;

        return file_put_contents ($newlocation . "/" . $filename , $img );
    }

但是当我检查网络时,一切似乎都很好......

我得到这个错误:419 未知状态

有什么想法吗?

【问题讨论】:

  • 听起来像 CSRF。在请求标头中是否有 csrf 令牌?您正在使用的库有一个使用 vue2 的标题部分,您可以像使用 ajax 一样将其删除:stackoverflow.com/questions/46466167/…
  • 非常感谢,就是这样!

标签: ajax laravel


【解决方案1】:

有时我们可能希望在不需要 CSRF_TOKEN 的情况下存在路由。我们可以简单地将这些 URI 或路由添加到 VerifyCsrfToken 中间件的 except 数组中,如下所示

<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;

class VerifyCsrfToken extends Middleware
{
 /**
  * The URIs that should be excluded from CSRF verification.
  *
  * @var array
  */
 protected $except = [
  'stripe/*',
  'http://example.com/foo/bar',
  'http://example.com/foo/*',
 ];
}

【讨论】:

  • 太好了,很有用!
猜你喜欢
  • 2019-07-16
  • 2018-05-26
  • 2019-08-05
  • 2018-07-18
  • 2018-09-20
  • 2018-08-24
  • 2021-08-28
  • 1970-01-01
  • 2020-05-11
相关资源
最近更新 更多