原因是所有的POST请求都要csrf_token验证,如果POST请求不带csrf_token就会提示419错误。

解决:打开文件:app\Http\Middleware\VerifyCsrfToken.php,

全部关闭
use Closure;

class VerifyCsrfToken extends Middleware

{

/**

* The URIs that should be excluded from CSRF verification.

*

* @var array

*/

protected $except = [

//

];

 

/**

* Handle an incoming request.

*

* @param  \Illuminate\Http\Request  $request

* @param  \Closure  $next

* @return mixed

*/

public function handle($request, Closure $next)

{

// Add this:

if($request->method() == 'POST')

{

return $next($request);

}

 

if ($request->method() == 'GET' || $this->tokensMatch($request))

{

return $next($request);

}

throw new TokenMismatchException;

}

 

}

2. 部分关闭

class VerifyCsrfToken extends Middleware

{

/**

* The URIs that should be excluded from CSRF verification.

*

* @var array

*/

protected $except = [

'api/*'

];

}

这样,post请求http://www.howingwah.com/api/***的接口都可以不用csrf验证
————————————————
版权声明:本文为CSDN博主「zm_21」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zm_21/article/details/88895443