【发布时间】:2021-03-16 14:22:00
【问题描述】:
我正在开发一个新的 lumen 项目,我正在尝试通过一个 Angular 项目与它进行交流。 我添加了一个中间件,以使用中间件为本地请求添加以下标头:
$response->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
->header('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, X-Token-Auth, Authorization');
但我仍然对 CORS 有疑问。
localhost/:1 Access to XMLHttpRequest at 'http://localhost:8080/auth/sign-in' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
Request URL: http://localhost:8080/auth/sign-in
Request Method: OPTIONS
Status Code: 405 Method Not Allowed
Remote Address: [::1]:8080
Referrer Policy: strict-origin-when-cross-origin
我使用 php 内置服务器运行该项目,以前从未遇到过这样的问题。 我检查了中间件是否执行,这里没有问题,所以我没有任何想法。我在寻求帮助时发现的只是添加标头或服务器配置,所以没有帮助。
【问题讨论】: