【发布时间】:2018-07-03 18:24:06
【问题描述】:
我正在尝试从我的 React 应用程序 (localhost:3000) 向我的 Laravel PHP 应用程序 (localhost:8000) 发出跨域请求。我相信我已将后端设置为接受跨域请求。我用这个:https://github.com/barryvdh/laravel-cors
我似乎拥有这个答案 (https://stackoverflow.com/a/38087435/1555312) 中的所有参数,所以我不明白为什么我的不起作用。当我使用 chrome 控制台时,我实际上看到了 200 响应 + 预期的正文。
这是我在控制台中看到的错误:
Failed to load http://localhost:8000/api/v1/upload-sessions: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
这是我的 POST 请求的样子:
OPTIONS 请求:
POST 请求:
发送了预期的响应,即使它抱怨 CORS 问题:
【问题讨论】: