为WebSocket连接配置身份验证标头(Configuring authentication headers for WebSocket connection)

编程入门 行业动态 更新时间:2024-10-28 19:35:28
为WebSocket连接配置身份验证标头(Configuring authentication headers for WebSocket connection)

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.

更多推荐

本文发布于:2023-08-02 16:14:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1378656.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:身份验证   Configuring   WebSocket   connection   headers

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!