【问题标题】:Check which browser type user is using in a socket connection检查用户在套接字连接中使用的浏览器类型
【发布时间】:2017-06-25 10:20:38
【问题描述】:

我正在使用节点 js 和套接字 io。我想知道用户在连接时使用的是哪个浏览器。

通过使用

sockets.on('connection', function(socket) {
    var ip_address = socket.conn..remoteAddress;  //this fetches the ip address
    var userbrowser = socket.conn. //am stuck here


});

如何获取用户在套接字中使用的浏览器类型

我已经检查了console.log(socket.conn),但我看不到任何有用的浏览器键

【问题讨论】:

标签: node.js sockets websocket socket.io


【解决方案1】:

这是怎么做的:

console.log("user-agent: "+socket.request.headers['user-agent']);

【讨论】:

    【解决方案2】:

    在你的套接字连接事件下你需要这样做

     io.on('connection', function(socket) {
       console.log(socket.request.headers)
       })
       //prints following info like 
    {
      "host": "192.168.1.77:4000",
      "user-agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:69.0) Gecko/20100101 Firefox/69.0",
      "accept": "*/*",
      "accept-language": "en-US,en;q=0.5",
      "accept-encoding": "gzip, deflate",
      "origin": "null",
      "connection": "keep-alive",
      "cookie": "io=_ffsFAYurGTLZunDAAAA"
    }
    

    【讨论】:

      猜你喜欢
      • 2012-06-14
      • 2019-06-06
      • 2011-11-12
      • 2022-01-22
      • 1970-01-01
      • 1970-01-01
      • 2011-04-21
      • 2010-11-13
      • 1970-01-01
      相关资源
      最近更新 更多