【发布时间】:2012-05-11 12:35:51
【问题描述】:
我想在浏览器端构造一个相对于页面 URI 的 WebSocket URI。说,在我的情况下转换 HTTP URI 像
http://example.com:8000/path
https://example.com:8000/path
到
ws://example.com:8000/path/to/ws
wss://example.com:8000/path/to/ws
我目前正在做的是将前 4 个字母“http”替换为“ws”,并附加“/to/ws”。有没有更好的办法呢?
【问题讨论】:
-
path/to/ws是什么意思?这究竟会导致什么?谢谢 -
"ws://" + window.location.host + ":6666" -done
标签: websocket uri relative-path