code

const socket = io('http://localhost:3000',{ query: { name: 'Клиент 1' // token: 'blablatoken' }, transportOptions: { polling: { extraHeaders: { 'x-clientToken': '5434543534364009blablatoken' } } } }); 

will return an error

 Request URL: http://localhost:3000/socket.io/?name=%D0%9A%D0%BB%D0%B8%D0%B5%D0%BD%D1%82%201&EIO=3&transport=polling&t=MFfoZYm Request Method: OPTIONS Status Code: 400 Bad Request 

and in response

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

and there is no Cookie header: io = uhcjDl0e_nz60VeJAAAA. and if I remove the additive header (extraHeaders), then everything works fine.

 Request URL: http://localhost:3000/socket.io/?name=%D0%9A%D0%BB%D0%B8%D0%B5%D0%BD%D1%82%201&EIO=3&transport=polling&t=MFfq8Dn Request Method: GET Status Code: 200 OK 

and there is a cookie header: io = uhcjDl0e_nz60VeJAAAA What is the problem? What did I miss?

  • It seems that with a welcome request, you have too large a request body, so server 400 returns. - Dmitry Miroshnichenko
  • thanks .... already solved the problem - Dilik Pulatov

1 answer 1

so decided (maybe not right)

changed

 transportOptions: { polling: { extraHeaders: { 'x-clientToken': '5434543534364009blablatoken' } } } 

on

 extraHeaders: { 'x-clientToken': '5434543534364009blablatoken' } 

But maybe I did not understand it, but there in the office. There was such an example sending a header