get可以,post提交失败,求解。

routes.php配置
Route::match(['get', 'post'], 'getlist/', 'Admin\UserController@getList');

1.png


2.png


post 的时侯返回是 Content-type:text/html; charset=UTF-8
但get的返回是 Content-Type:application/json
代码就是这向句了
public function getList()
{
$array=[];
$user = DB::table('users')->paginate(15);
$array['page']=$user->currentPage();
$array['rows']=$user->items();
$array['total']=$user->total();

return response()->json($array);
}
已邀请:

yuzhahui

赞同来自:

自已回复一下........
--------------------------修改VerifyCsrfToken[ App\Http\Middleware]
namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
use Closure;
use Illuminate\Session\TokenMismatchException;
class VerifyCsrfToken extends \Illuminate\Foundation\Http\Middleware\VerifyCsrfToken
{
/**
 * The URIs that should be excluded from CSRF verification.
 *
 * @var array
 */
protected $except = [

];

public function handle($request, Closure $next)
{
    if ($this->isReading($request) || $this->excludedRoutes($request) || $this->tokensMatch($request))
    {
        return $this->addCookieToResponse($request, $next($request));
    }

    throw new TokenMismatchException;
}

protected function excludedRoutes($request)
{
    $routes = [
        'getlist'
    ];

    foreach($routes as $route)
        if ($request->is($route))
            return true;

    return false;
}
}

---------------------------------------------------
$routes里就是允许的路径了 laravel-v 5.1.4

要回复问题请先登录注册