首页 > 解决方案 > 无法接收 SocketIO 客户端的“auth”参数

问题描述

这就是我访问 SocketIO 服务器的方式

var socket = io('http://localhost:3001', {
  query: {
    token : "XXXX"
  },
  withCredentials: false,
  allowEIO3: true,
  auth: {
    token: "abc"
  }
});

在后端我得到query但不是auth参数:

{"headers":{"host":"localhost:3001","user-agent":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0","accept":"*/*","accept-language":"en-US,en;q=0.5","accept-encoding":"gzip, deflate","origin":"http://localhost:4001","dnt":"1","connection":"keep-alive","referer":"http://localhost:4001/","sec-gpc":"1"},"time":"Tue Jun 01 2021 22:29:48 GMT+0530 (India Standard Time)","address":"::ffff:127.0.0.1","xdomain":true,"secure":false,"issued":1622566788895,"url":"/socket.io/?token=XXXX&EIO=3&transport=polling&t=Nd8X5xy","query":{"token":"XXXX","EIO":"3","transport":"polling","t":"Nd8X5xy"}}

标签: socket.io

解决方案


推荐阅读