Lumen 5.5,barryvdh / laravel-cors包不起作用

时间:2017-12-02 10:17:12

标签: angular cors lumen lumen-5.5

我正在努力解决角色问题。实际上我是流明的新手,我正在向lumen发送登录请求(来自角4项目)。我已经搞砸了barryvdh / laravel-cors包并进行了以下配置。但它仍然不起作用。我不知道哪里出错了。 它仍然会出现以下错误

Failed to load http://localhost:8000/api/v1/login: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
  

自举/ app.php

$app->configure('cors');

$app->middleware([
   Barryvdh\Cors\HandleCors::class
]);

$app->register(Barryvdh\Cors\LumenServiceProvider::class);
  

请求标题

Accept:*/*
Accept-Encoding:gzip, deflate, br
Accept-Language:en-US,en;q=0.9,hi;q=0.8
Access-Control-Request-Headers:content-type
Access-Control-Request-Method:POST
Connection:keep-alive
Host:localhost:8000
Origin:http://localhost:4200
User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36
  

响应标头

    Access-Control-Allow-Headers:content-type
Access-Control-Allow-Methods:POST
Access-Control-Allow-Origin:*
Cache-Control:no-cache, private
Connection:close
Content-type:text/html; charset=UTF-8
Date:Sat, 02 Dec 2017 12:37:23 +0100
Date:Sat, 02 Dec 2017 11:37:23 GMT
Host:localhost:8000
X-Powered-By:PHP/7.1.4

1 个答案:

答案 0 :(得分:0)

如果你在localhost中有牵引项目,那不是流明问题,有一个 config 请求流明项目请注意{{3} }