CORS 预检 return Access-Control-Allow-Origin 但响应挂起

CORS preflight return Access-Control-Allow-Origin but response hangs on

我正在执行 CORS 请求,服务器已返回给我这样一组 headers 用于预检 OPTIONS 请求。

Access-Control-Allow-Headers:authorization
Access-Control-Allow-Methods:POST, OPTIONS
Access-Control-Allow-Origin:*
Connection:Keep-Alive
Content-Length:0
Content-Type:application/json
Date:Sat, 09 Dec 2017 21:02:47 GMT
Keep-Alive:timeout=5, max=100
Server:Apache

并且下一个 POST 请求已成功执行,但我仍然在控制台中收到错误消息。

No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'bla-bla-bla.com' is therefore not allowed access. 

If an opaque response serves your needs, 
set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

或者 POST 响应是否也应向我发送 header Access-Control-Allow-Origin:*?

我是否需要从客户端执行其他操作才能执行 CORS?谢谢:)

预检和实际响应都必须授予 Access-Control-Allow-Origin 权限。

如果只有prelight,那么事件的顺序是:

  1. JavaScript 提出请求
  2. 浏览器发出预检请求
  3. 服务器发送预检响应
  4. 浏览器检查 CORS(通过)
  5. 浏览器发出实际请求
  6. 服务器发送实际响应
  7. 浏览器检查 CORS(失败)
  8. 浏览器拒绝读取对 JS 的响应