Home > Backend Development > PHP Tutorial > Laravel 如何关闭跨域请求验证

Laravel 如何关闭跨域请求验证

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 13:13:06
Original
1872 people have browsed it

使用中间件来关闭跨域请求验证

首先在app/Http/Middleware文件夹内添加一个CORS.php文件 使用命令

  php artisan make:middleware CORS
Copy after login


修改php文件内容 内容如下

<?php namespace App\Http\Middleware;  use Closure;  class CORS  {   /**  * Handle an incoming request.  *  * @param \Illuminate\Http\Request $request  * @param \Closure $next  * @return mixed  */ public function handle($request, Closure $next) {  return $next($request)->header('Access-Control-Allow-Origin','*')          ->header('Access-Control-Allow-Methods','POST, GET, OPTIONS, PUT, DELETE')          ->header('Access-Control-Allow-Headers','Content-Type, Accept, Authorization, X-Requested-With'); }}
Copy after login


然后根据官方文档 修改app/Http/Kernel.php文件,将CORS中间件注册到全局中间件即可。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template