这是我尝试过的
中间件
return $next($request)
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Credentials', 'true')
->header('Access-Control-Allow-Headers', 'Origin, Content-Type, Authorization, X-Requested-With, Accept, X-Token-Auth, Application')
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
API 路由
Route::group(['middleware' => ['cors', 'auth:api']], function() {
Route::options('{any}');
Route::post('user/profile','UserController@profile');
内核.php
protected $routeMiddleware = [
'cors' => \App\Http\Middleware\Cors::class,
但是,我仍然在来自另一个来源的 API 调用中收到此错误。
对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。
任何原因?
炎炎设计
人到中年有点甜