gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 16:42:28 25 4
gpt4 key购买 nike

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

让我们逐步描述问题:

  1. 从应用程序到 REST API 的 XHR 请求。
  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

所以我刚刚将缺少的 CORS header 列表添加到我的 web.api 中。

我希望这对某人有帮助。

关于javascript - CORS 预检请求的奇怪问题在 IE 11 上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27908661/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com