Max*_*ino 7 websocket redis node.js cors socket.io
我在端口8082上使用Node.js,在端口80上使用Apache.
一切正常,并且浏览器开始显示错误消息"400 Bad Request",CORS错误.
服务器正在设置CORS标头.如您所见,我也在使用Redis适配器.
var io = require('socket.io').listen(8082);
io.adapter(redis({ host: '127.0.0.1', port: 6379 }));
io.set('origins', 'domain.com:*');
Run Code Online (Sandbox Code Playgroud)
不能说为什么有些时候一切正常,有些时候没有.当Socket.io尝试从pooling升级到websocket时,总会发生错误.
当我使用来自https://cdn.socket.io/socket.io-1.0.6.js的客户端时,我得到的错误更少.
当我使用socket.io-1.0.6.js的本地引用时,错误会以更高的频率发生.找不到错误模式.
在错误之后,我重新启动Node.js服务器,尝试一些请求,一次又一次地工作,错误.有时无需重新启动服务器即可再次运行.
请求标头示例
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3
Cookie io=RjKzZ6Y1OTQeSEsPAAAL; SGM_DESENV=cb5ae798c2f6f5d3f38c6ed16a6e4696
Host 200.238.251.79:8082
Origin http://200.238.251.79
Referer http://200.238.251.79/maximiliano/sgp/admin/custodiacompartilhada/add
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:29.0) Gecko/20100101 Firefox/29.0
Run Code Online (Sandbox Code Playgroud)
响应标头示例
Access-Control-Allow-Credentials true
Access-Control-Allow-Origin http://200.238.251.79
Connection keep-alive
Content-Length 101
Content-Type application/octet-stream
Date Fri, 25 Jul 2014 16:10:26 GMT
Set-Cookie io=9OYcCmU24IyzrAS3AAAM
Run Code Online (Sandbox Code Playgroud)
错误消息
NetworkError: 400 Bad Request - http://200.238.251.79:8082/socket.io/?EIO=2&transport=polling&t=1406304539856-2&sid=RjKzZ6Y1OTQeSEsPAAAL
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://200.238.251.79:8082/socket.io/?EIO=2&transport=polling&t=1406304539856-2&sid=RjKzZ6Y1OTQeSEsPAAAL This can be fixed by moving the resource to the same domain or enabling CORS.
Run Code Online (Sandbox Code Playgroud)
小智 0
CORS 不允许在域名中使用通配符。
您要么必须允许来自所有域:
io.set('origins', '*');
Run Code Online (Sandbox Code Playgroud)
或指定端口:
io.set('origins', 'http://200.238.251.79:8082');
Run Code Online (Sandbox Code Playgroud)
(在另一个端口上请求意味着 CORS)
归档时间: |
|
查看次数: |
3579 次 |
最近记录: |