【问题标题】:CORS: No 'Access-Control-Allow-Origin' header is present even though response is 200?CORS:即使响应为 200,也不存在“Access-Control-Allow-Origin”标头?
【发布时间】: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 问题:

【问题讨论】:

    标签: https cors


    【解决方案1】:

    您需要在响应而不是请求上设置Access-Control-Allow-...

    一旦您从请求中删除它,您可能就不需要预检,因此不会发生 OPTIONS 请求。

    【讨论】:

      猜你喜欢
      • 2016-10-30
      • 1970-01-01
      • 2020-09-21
      • 2016-05-07
      • 2016-10-30
      • 2019-06-19
      • 2021-05-23
      • 2016-11-06
      相关资源
      最近更新 更多