IE上的socket.io-client出现CORS错误

时间:2015-05-06 20:41:12

标签: node.js internet-explorer socket.io cors

我遇到IE和CORS的问题。

在我的页面" mysite.com",我这样做:

客户端:

<script src="http:// assets.mysite.com/bundle.js"> //without the space

在资产服务器上,我有:

app.use(function (req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "X-Requested-With");
  next();
});

bundle.js是一个浏览器模块,连接到套接字服务器:

var socket = require('socket.io-client')("http: //mysocketserver.com:5000/api");

在Chrome和Firefox上没问题,一切都完美加载,连接建立等等。在IE上(令人惊讶的是)事情并不是那么好。

SEC7118: XMLHttpRequest for http://mysocketserver:5000/socket.io/?EIO=3&transport=polling&t=1430944033665-4&sid=jvRj85_i_1ZgwTumAABK required Cross Origin Resource Sharing (CORS).

我检查了一切。 IE使用与Chrome和FF相同的传输,套接字请求在所有浏览器上都有以下标头:

Access-Control-Allow-Credentials    true
Access-Control-Allow-Origin http:// mysite.com

然而,IE拒绝连接,我无法弄清楚原因。

1 个答案:

答案 0 :(得分:-1)

因为它是IE;)特别是IE 8/9跨域会有这样的问题。尝试使用XDomain,它对我有用并解决了这些问题。