socketio / socket.io-client

Realtime application framework (client)
https://socket.io
10.62k stars 3.04k forks source link

403 Forbidden on POST with Bad handshake method #1390

Closed zhangzheng7856 closed 3 years ago

zhangzheng7856 commented 3 years ago

return {"code":2,"message":"Bad handshake method"}

what it mean?

and how can i resolve it?

lcherone commented 3 years ago

Check client and server versions are the same, connecting to v3.0.0 server with a v2.x.x client won't work, with this exact error. Its due to the sid not being passed along.

darrachequesne commented 3 years ago

@lcherone I don't think that's related to the v3 release, as it was not actually released when the issue was created 5 days ago. Or did that happen with a release candidate version?

@zhangzheng7856 could you please give additional details? Are you using the JS server/client? Which version?

The error is thrown here: https://github.com/socketio/engine.io/blob/4.0.1/lib/server.js#L137

Which means the server receives an HTTP request that is not a GET, but without a sid, which is invalid.

Possibly related: https://github.com/socketio/engine.io-client/issues/636

travisnguyen20 commented 3 years ago

@lcherone You are correct. I have the same issue because the client-side using version 3.0.0 that release 2 days ago while the server-side uses laravel-echo-server that using 2.x.x version.

lcherone commented 3 years ago

@travisnguyen20 It happened to me too, had old project which used 2.3.0 which just copied, then when coding the server part I did npm i socket.io which installed v3, then spent a few hours debugging why it's broke, then noticed the version diffs, out of a whim changed socket.io-client to match "socket.io-client": "^3.0.0", run npm i and walla all working again. Thought id look here for the same issue and then posted the suggestion. Think it might catch a few peeps out as error is not at all helpful, and one thing I noticed is that it works just fine in node but will error only when used in the browser.

Is all todo with the recent sid change I think, as it was borking on this line: https://github.com/socketio/socket.io-client/blob/master/lib/socket.ts#L228 if over websocket, but when doing polling would get the OPs Bad handshake json error.

Edit, here's an example of it not working: https://glitch.com/edit/#!/socket-io-sid?path=views%2Findex.html%3A13%3A22

dalexhd commented 3 years ago

Okay... 3 hours facing this problem xd. My head is literally exploded right now!

So it seems I'm not the only one with this problem right?

darrachequesne commented 3 years ago

@dalexhd I'm not sure I understand. Do you have the same version of Socket.IO on both sides?

dalexhd commented 3 years ago

Yes the same versión of socket.io client.

anselmpaul commented 3 years ago

@darrachequesne I'm hijacking this thread for a similar issue, mentioned here https://github.com/socketio/socket.io-client/issues/1140#issuecomment-728840985. Could you clarify if this is a bug or a breaking change between v2.3 and v3.0?

darrachequesne commented 3 years ago

This is indeed a bug. It should be fixed by https://github.com/socketio/engine.io-client/commit/1c8cba8818e930205918a70f05c1164865842a48, included in engine.io-client@4.0.4 and socket.io-client@3.0.3 (https://github.com/socketio/socket.io-client/commit/625d146f28376cea88aa8379891d02d845915154).

Can anyone confirm?

mcarnoky001 commented 3 years ago

I installed version 3.0.3 on client and server, and this issue still persists.

darrachequesne commented 3 years ago

I'm closing this, as I think the issue is now fixed.

@mcarnoky001 could you please open an issue with a reproducing test case? Thanks!