问题
[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?
<!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