We have to implement WebSocket connection with third-party WebSocket server. But they are using Authorization header for establishing a connection between WebSocket client and WebSocket server. But I could not find any solution to add Authorization header in WebSocket client during connection. Please help me to resolve this issue.
This is my code I am using
var ws = new WebSocketClient();
var headers ={Authorization: 'token'}
ws.on('connectFailed', function(error) {
console.log('Connect Error: ' + error.toString());
});
ws.on('connect', function(connection) {
console.log('WebSocket Client Connected');
});
ws.connect('wss://url', '',headers);
Response is like this
Server responded with a non-101 status: 400 Bad Request
Response Headers Follow:
server: nginx/1.11.7
date: Thu, 11 Jul 2019 19:49:58 GMT
content-type: text/html
content-length: 31
connection: keep-alive