如何在另一个应用程序中处理Laravel应用程序中的帖子请求?

时间:2017-05-27 09:22:32

标签: php laravel

我期待来自其他系统的Laravel 5.2应用程序发布请求,当我处理它时,我收到:

  

VerifyCsrfToken.php第67行中的TokenMismatchException:

通常当我发送帖子表格时,我会添加代码{{csrf_field()}},但在这种情况下,请求来自不同的应用程序。那么如何正确处理呢?

2 个答案:

答案 0 :(得分:2)

您可以将应从验证中排除的URI添加到$except中间件中的VerifyCsrfToken属性。

<?php

namespace App\Http\Middleware;

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

class VerifyCsrfToken extends BaseVerifier
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'api/*',
    ];
}

Documentation

答案 1 :(得分:1)

您可以从CSRF保护中排除来自其他应用程序的reuqest发送的URI。这在文档here

中有所描述