WebSocket Handshake - Unexpected response code 200 - AngularJs and Spring Boot

后端 未结 3 1666
生来不讨喜
生来不讨喜 2020-12-31 07:54

When I tried to establish websocket communication between AngularJS app and Spring Boot I\'m getting the error: Error during websocket handshake - Unexpected respons

3条回答
  •  长情又很酷
    2020-12-31 08:37

    I had a similiar problem, I was testing my websocket connection using an chrome plugin (Simple WebSocket Client) and was trying to connect to ws://localhost:8080/handler/ which is defined in my code as registry.addEndpoint("/handler").setAllowedOrigins("*").withSockJS(); but unexpected error 200 was occuring. I've fixed this by appending /websocket to my client request string on the chrome extension, so what you could try is to change in your JS file the following line:

    var ws = $websocket.$new('ws://localhost:8080/socket');
    

    to

     var ws = $websocket.$new('ws://localhost:8080/socket/websocket');
    

    I dont know the reason why this fixed it in my case i just randomly stumbled upon it, if some1 could clarify it more it would be really nice :)

提交回复
热议问题