Getting Response code was not 101: 400 in Java Websocket API client
Asked Answered
U

1

6

I have the following WebSocket client code in Java.

final ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().build();

            ClientManager client = ClientManager.createClient();
            client.connectToServer(new Endpoint() {

                @Override
                public void onOpen(Session session, EndpointConfig config) {
                    try {
                        session.addMessageHandler((MessageHandler.Whole<String>) message -> {
                            System.out.println("Received message: "+message);
                        });
                        session.getBasicRemote().sendText(SENT_MESSAGE);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }, cec, new URI("wss://ws.bitso.com"));
        } catch (Exception e) {
            e.printStackTrace();
        }

For some reason, I'm getting this error.

org.glassfish.tyrus.core.HandshakeException: Response code was not 101: 400

What could be the reason?

Unclad answered 28/11, 2017 at 2:42 Comment(0)
U
5

I solved it.

I was missing a slash at the end of the hostname.

It should be wss://ws.bitso.com/

Unclad answered 28/11, 2017 at 2:44 Comment(2)
so you may as well delete this question thenBinomial
@ScaryWombat it can help others.Unclad

© 2022 - 2024 — McMap. All rights reserved.