我嘗試發送有關 webSocket 標頭的信息,并在連接時在服務器上讀取它。像:客戶端代碼很簡單:ws = await WebSocket.connect('ws://localhost.com:36485', headers: { 'codeName': 'Something', },);服務器代碼:var WebSocketServer = require('ws').Server , wss = new WebSocketServer({ port: 36485 });wss.on('connection', function connection(ws) { console.log(ws.upgradeReq.headers); ws.on('message', function incoming(message) { console.log('received: %s', message); });});我的例外是:類型錯誤:無法讀取未定義的屬性“標題”
如何從 websocket 連接讀取標頭
一只斗牛犬
2021-12-12 11:03:02