close

[Solved] WebSocket connection failed: Error during WebSocket handshake: Unexpected response code: 400

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error WebSocket connection failed: Error during WebSocket handshake: Unexpected response code: 400 in javascript. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How WebSocket connection failed: Error during WebSocket handshake: Unexpected response code: 400 Error Occurs?

e. Today I get the following error WebSocket connection failed: Error during WebSocket handshake: Unexpected response code: 400 in javascript.

How To Solve WebSocket connection failed: Error during WebSocket handshake: Unexpected response code: 400 Error ?

  1. How To Solve WebSocket connection failed: Error during WebSocket handshake: Unexpected response code: 400 Error ?

    To Solve WebSocket connection failed: Error during WebSocket handshake: Unexpected response code: 400 Error I solved this by changing transports from 'websocket' to 'polling'
    var socket = io.connect('xxx.xxx.xxx.xxx:8000', { transports: ['polling'] });

  2. WebSocket connection failed: Error during WebSocket handshake: Unexpected response code: 400

    To Solve WebSocket connection failed: Error during WebSocket handshake: Unexpected response code: 400 Error I solved this by changing transports from 'websocket' to 'polling'
    var socket = io.connect('xxx.xxx.xxx.xxx:8000', { transports: ['polling'] });

Solution 1

This worked for me with Nginx, Node server and Angular 4

Edit your nginx web server config file as:

server {
listen 80;
server_name 52.xx.xxx.xx;

location / {
    proxy_set_header   X-Forwarded-For $remote_addr;
    proxy_set_header   Host $http_host;
    proxy_pass         "http://127.0.0.1:4200";
    proxy_http_version 1.1;
    proxy_set_header   Upgrade $http_upgrade;
    proxy_set_header   Connection "upgrade";
}

Solution 2

I solved this by changing transports from ‘websocket’ to ‘polling’

   var socket = io.connect('xxx.xxx.xxx.xxx:8000', {
      transports: ['polling']
   });

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment