跨域连接无法通过浏览器工作

时间:2018-09-10 15:28:47

标签: socket.io node-cluster socketcluster

我正在尝试连接到外部域,并在socketio和socketcluster中进行了相同的测试,出于某种原因,socketio连接可以正常工作,而套接字群集却没有连接

套接字IO代码

        var subscriptionUrl = 'https://streamer.cryptocompare.com/'

        var socket = io.connect(subscriptionUrl)

        socket.emit('SubAdd', {
            subs: ['5~CCCAGG~BTC~USD']
        })

        socket.on("m", function (message) {console.log('got message')}

套接字群集代码

var options = {
                hostname: 'streamer.cryptocompare.com',
                port: 443,
                secure: true,
                rejectUnauthorized: false
            }

        // Initiate the connection to the server
        var socket = socketCluster.create(options);

        socket.on('connect', function () {
            console.log('CONNECTED');
        });

我希望我什么都没错过,不过我发现开发人员工具的“网络”标签下的网址有所不同

套接字IO 生成的URL https://streamer.cryptocompare.com/socket.io/?EIO=3&transport=websocket&sid=9KvMOnR02fTySfzTAFg3

请求标头

GET /socket.io/?EIO=3&transport=websocket&sid=9KvMOnR02fTySfzTAFg3 HTTP/1.1
Host: streamer.cryptocompare.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:62.0) Gecko/20100101 Firefox/62.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Sec-WebSocket-Version: 13
Origin: null
Sec-WebSocket-Extensions: permessage-deflate
Sec-WebSocket-Key: AFYCl0wCU44wzhPAvBuUag==
Cookie: io=9KvMOnR02fTySfzTAFg3
DNT: 1
Connection: keep-alive, Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket

响应标题

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: UqbJlC7wJDmalDqf4ouCMvyE9eM=
Sec-WebSocket-Extensions: permessage-deflate

SocketCluster 生成的URL https://streamer.cryptocompare.com/socketcluster/ 网址不包含sid和运输

请求标头

GET /socketcluster/ HTTP/1.1
Host: streamer.cryptocompare.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:62.0) Gecko/20100101 Firefox/62.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Sec-WebSocket-Version: 13
Origin: null
Sec-WebSocket-Extensions: permessage-deflate
Sec-WebSocket-Key: oK5xxYb8Vjkvy6Byc2ps+g==
Cookie: io=9KvMOnR02fTySfzTAFg3
DNT: 1
Connection: keep-alive, Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket

未生成响应头 我假设console.log中的connect语句至少应该执行,或者如果我忽略了某些内容。某些方向是超级赞赏。谢谢

0 个答案:

没有答案