Socket.io gets “bad handshake method” on Firefox, but not Chrome or Safari

回眸只為那壹抹淺笑 提交于 2021-01-01 06:30:24

问题


[This is a duplicate of socket.io issue #2717 on Github. No answers there, I'd love to get some troubleshooting hints...]

I have a test page (below) that creates a socket.io connection back to the server, then listens for and logs 'time' messages. It works as expected for recent Chrome and Safari on OSX 10.10.5. I'm using Socket.io 1.5.0 for all tests.

With Firefox 49.0.1, each POST request gets a response with bad handshake method. There is no Socket.io connected... message in the console, and no time messages arrive (see image). Other interesting info about the POST is:

- Params: EIO:3, t: LUuPeKr, transport:polling
- POST raw data: "1:1"

The test page connects back to a create-react-app app (0.6.1) that proxies the request to my own server on localhost:3001. As noted above, this page works as expected with Chrome and Safari.

What other info could I provide to debug this?

image

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>SOCKET.IO TEST PAGE</title>
</head>
<body>
<h1>Socket.io Test Page</h1>

<script src="/socket.io/socket.io.js"></script>
<script>
    var socket = io();
    socket.on('connect', function(data){
        console.log("Socket.io connected...");
    });

    socket.on('time', function (data) {
        console.log(data);
    });
</script>
</body>
</html>

回答1:


I was getting a bad handshake method error in chrome as well and fixed it by downgrading to socket.io 2.3.1 and the same for socketio-client




回答2:


Answering my own post: Got a solution over on github. https://github.com/socketio/socket.io/issues/2717 tells about the fix to the socket.io code so that it always requests '*/*' instead of using Firefox's default.



来源:https://stackoverflow.com/questions/40034120/socket-io-gets-bad-handshake-method-on-firefox-but-not-chrome-or-safari

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!