WebSocket地址可以携带参数吗? [英] Can WebSocket addresses carry parameters?

查看:404
本文介绍了WebSocket地址可以携带参数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ws://myserver.com/path?param = 1 有效的WebSocket地址?

Is ws://myserver.com/path?param=1 a valid WebSocket address ?

地址 http://myserver.com/path?param=1 (注意它现在是 http 而不是 ws )适用于 wscat ,但我无法在浏览器上运行。

The address http://myserver.com/path?param=1 (notice it's now http and not ws) works fine with wscat, but I can't get it working on the browser.

推荐答案

ws://myserver.com/path?param = 1 是一个有效的WebSocket URI。但是,WebSocket服务器应用程序可以访问路径和查询字符串的方式将根据您使用的WebSocket服务器框架而有所不同。

ws://myserver.com/path?param=1 is a valid WebSocket URI. However, the way that your WebSocket server application can access the path and query string will differ depending on what WebSocket server framework you are using.

如果您使用的是节点。 js einaros / ws 库,然后在你的websocket连接对象将具有查询字符串的完整路径 upgradeReq.url

If you are using the Node.js einaros/ws library, then in your websocket connection object will have the full path with the query string at upgradeReq.url.

例如:

wss.on('connection', function(ws) {
    console.log("url: ", ws.upgradeReq.url);
};

将打印 url :/ path?param = 1 连接到 ws://myserver.com/path?param = 1

这篇关于WebSocket地址可以携带参数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆