我正在尝试使用curl post方法提交表单。我已将csrf令牌正确设置为表单。但它在VerifyCsrfToken.php第46行显示TokenMismatchException:。我被卡在网上并在网上搜索。但是没有得到任何解决方案。
答案 0 :(得分:0)
您的表单应如下所示
@extends('layout.main')
@section('content')
<form action="{{URL::route('give-the-route')}}" method="post">
<input type="text" name="name" placeholder=" Title">
<textarea name="description" cols="45" rows="5"placeholder="Brief Description "></textarea>
<input name="_token" type="hidden" value="{{csrf_token()}}">
<input type="submit" value="Publish"><br>
</form>
@stop
我的意思是不要忘记写下面一行
<input name="_token" type="hidden" value="{{csrf_token()}}">
答案 1 :(得分:0)
@extends('layout.main')
@section('content')
<form action="{{URL::route('give-the-route')}}" method="post">
<input type="text" name="name" placeholder=" Title">
<textarea name="description" cols="45" rows="5"placeholder="Brief Description "></textarea>
<!-- dont forgot to use this -->
<input name="_token" type="hidden" value="{{csrf_token()}}">
<input type="submit" value="Publish">
</form>
@stop
答案 2 :(得分:-1)
CSRF现在是在Laravel 5的App \ Http \ Kernel.php中全局注册的“中间件”。删除它将默认不提供CSRF保护(Laravel4行为)。 在Kernel.php中注释掉或删除此行
之前:
protected $middleware = [
'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode',
'Illuminate\Cookie\Middleware\EncryptCookies',
'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse',
'Illuminate\Session\Middleware\StartSession',
'Illuminate\View\Middleware\ShareErrorsFromSession',
'App\Http\Middleware\VerifyCsrfToken',
];
后:
protected $middleware = [
'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode',
'Illuminate\Cookie\Middleware\EncryptCookies',
'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse',
'Illuminate\Session\Middleware\StartSession',
'Illuminate\View\Middleware\ShareErrorsFromSession',
// 'App\Http\Middleware\VerifyCsrfToken',
];