CORS 预检请求的奇怪问题在 IE 11 上失败

Strange issue with CORS preflight request fails on IE 11

问题是 POST 查询在 IE11 上失败,但在所有其他浏览器中它似乎工作正常。

让我们逐步描述问题:

  1. 从应用程序到 REST 的 XHR 请求 API。
  2. Preflight OPTIONS 请求(请求参数如下)
Accept:                         */*
Origin:                         https://app.example.com
Access-Control-Request-Method:  POST
Access-Control-Request-Headers  content-type, accept
:                               
Accept-Encoding:                gzip, deflate
User-Agent:                     Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko
Host:                           api.example.com
Content-Length:                 0
Connection:                     Keep-Alive
Cache-Control:                  no-cache
  1. 预检请求响应参数为:
X-Powered-By:                   Sugar
Access-Control-Allow-Origin:    https://app.example.com
Vary:                           Origin
Access-Control-Allow-Credentia  true
ls:                             
Access-Control-Allow-Methods:   GET,POST,DELETE,OPTIONS
Access-Control-Allow-Headers:   X-Requested-With,X-HTTP-Method-Override,Content-Type,Accept
set-cookie:                     sugar.sid=s%Pb9OoTTPUkVw%2F2vUPoFMNG
                                LMXACSkQevo; Path=/; Expires=Thu, 15 Jan 2015 18:27:07 GMT; HttpOnly; Secure
Date:                           Mon, 12 Jan 2015 18:27:07 GMT
Connection:                     close
  1. preflight请求参数后的真实HTTP请求:
Accept:           application/json
Content-Type:     application/json
Referer:          https://app.example.com/
Accept-Language:  en-US
Origin:           https://app.example.com
Accept-Encoding:  gzip, deflate
User-Agent:       Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko
Host:             api.example.com
Content-Length:   9
Connection:       Keep-Alive
Cache-Control:    no-cache
Cookie:           sugar.sid=s%3A-%2FGF1YoFmRfmBsxK4vLBoGjY5NT0QoYvf5s;
  1. 最后响应参数:
Content-Type:    application/json; charset=utf-8
Content-Length:  72
Vary:            Accept-Encoding
Date:            Mon, 12 Jan 2015 18:27:07 GMT
Connection:      close
  1. 基本上响应以 IE 错误结束:来源:https://app.example.com 在 Access-Control-Allow-Origin header 中找不到。第一个请求是否还需要 Access-**-Origin header,它似乎丢失了。

也按照CORS流程图调试问题,但是没发现http://www.html5rocks.com/static/images/cors_server_flowchart.png

我正在使用带有 node-cors 模块 + 修改选项的 Node.js Express 服务器。

我在我的网站上使用 Fiddler 调试这个问题并收到这条消息:

HTTP/1.1 400 Bad Request
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Date: Mon, 12 Sep 2016 19:40:20 GMT
Content-Length: 103

{"Message":"The collection of headers 'accept,if-modified-since,cache-control,pragma' is not allowed."}

CORS the collection of headers accept,if-modified-since,cache-control,pragma

所以我刚刚在 web.api 中添加了缺少 headers 到 CORS 的列表。

我希望这对某人有所帮助。