I get a status 200 when connecting to the websocket, but it is an error?

后端 未结 6 1400
名媛妹妹
名媛妹妹 2020-12-02 22:54

My error shows up in the console of my browser:

\"WebSocket connection to \'ws://localhost:32768/DspClusterWebServices/myHandler\' failed: Unexpected response

相关标签:
6条回答
  • 2020-12-02 23:14

    Please check http://procbits.com/connecting-to-a-sockjs-server-from-native-html5-websocket!

    After you append /websocket (to your URL), it will give you the error

    Failed to parse Origin header value [null]

    ;) , which then will in turn lead you to that link.

    You'll have to add .setAllowedOrigins("*") to your addHandler() method, and then it could finally work!

    0 讨论(0)
  • 2020-12-02 23:15

    For those guys like me who use angular + springboot and got this error. please check if you have enabled the redirect or forward all non api endpoint request back to index.html. like:

    @RequestMapping(value = "/**/{[path:[^\\.]*}")
        public String redirect() {
            // Forward to home page so that route is preserved.
            return "forward:/index.html";
        }
    

    If you do, disable it and you will get 101

    0 讨论(0)
  • 2020-12-02 23:15

    Don't know if this is too late but a solution that I stumbled upon is simply appending the string /websocket after the websocket endpoint that you declared in the spring boot server. This will help keep both the forwarding logic and connect and establish a websocket connection.

    0 讨论(0)
  • 2020-12-02 23:24

    As my another answer:[https://stackoverflow.com/a/53272666/2930417][1]

    I use springboot 2 +STOMP。

    remove .withSockJS(),then everything is ok.

    I don't know the reason,but works for me.

    0 讨论(0)
  • 2020-12-02 23:24

    Have a look at the specification . The server should respond with 101 to signal protocol change from http to ws.

    0 讨论(0)
  • 2020-12-02 23:29

    Please check that if 'ws://localhost:32768/DspClusterWebServices/myHandler' is correct.

    0 讨论(0)
提交回复
热议问题