IIUC,当我创建一个WebSocket时,一个HTTP请求被发送到指定的URL,包含一个升级请求。 通常是将认证信息与此升级请求一起传递,还是应该单独执行?
var websocket = new WebSocket("ws://domain:port/foo"); // Can I include authentication headers with the initial upgrade HTTP request?IIUC, when I create a WebSocket an HTTP request is sent to the specified URL, containing an upgrade request. Is it typicaly to pass authentication information along with this upgrade request, or should it be performed separately?
var websocket = new WebSocket("ws://domain:port/foo"); // Can I include authentication headers with the initial upgrade HTTP request?最满意答案
您应该通过网络进行身份验证,返回一个cookie,然后再次连接到websocket服务器,携带cookie。 WS服务器可以验证cookie
如果没有基于cookie的身份验证或者只是不可能(如另一个域中的WS服务器),则必须创建自己的请求 - 响应消息以进行登录。
You should do the authentication through web, return a cookie and then connect to the websocket server again, carrying the cookie. The WS server can validate the cookie
If there is no cookie based authentication or it is just not possible (like the WS server in another domain), you will have to create your own request-response messages for login.
更多推荐
发布评论