Laravel5:如何禁用CSRF过滤器?

时间:2015-08-08 09:13:00

标签: laravel laravel-5

我想在Laravel 5中禁用CSRF过滤器。我该怎么办?

我从"\App\Http\Middleware\VerifyCsrfToken::class,"删除了Illuminate\Foundation\Http\Kernel。但是,我收到了HTTP 403(Forbidden)错误。

class Kernel extends HttpKernel {

    /**
     * The application's global HTTP middleware stack.
     *
     * @var array
     */
    protected $middleware = [
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
        \App\Http\Middleware\EncryptCookies::class,
        \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        \App\Http\Middleware\App::class
    ];


http://laravel.io/forum/11-14-2014-disabling-the-csrf-middleware-in-laravel-5

Ajax访问

<script>
      $(document).ready(function(){
          $("#frm").submit(function(e){
              e.preventDefault();

              $.ajax({
                  type: 'post',
                  url : 'http://example.com/contact',
                  data : 'address=1',
                  success : function(data){
                      console.log(data);
                  }
              },"json");
          });
      });
</script>

为什么我要禁用CSRF是我无法通过ajax访问的。请看下面我的另一个问题......

Laravel5 CSRF过滤器:返回HTTP 422错误 Laravel5 CSRF Filter: Return HTTP 422 Error

任何帮助都会有所帮助。感谢。

0 个答案:

没有答案