EventSource中的HTTP授权标头(服务器发送事件) [英] HTTP Authorization Header in EventSource (Server Sent Events)

查看:1984
本文介绍了EventSource中的HTTP授权标头(服务器发送事件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将授权标头设置为HTML5 EventSource。由于Websockets出现后服务器发送事件似乎被废弃,我找不到任何有用的文档。我已经找到的方法是在url中传递授权数据...但我不喜欢这种方法。



我使用AngularJS并设置拦截器$ httpProvider,但EventSource不会被AngularJS拦截,所以我不能添加任何头文件。

解决方案

EventSource没有 API ,用于将HTTP标头发送到服务器。我在使用SSE建立实时聊天功能时也遇到了这个问题。



但是我认为如果您的SSE服务器与您的服务器是同一台服务器,Cookie将自动发送认证服务器。

I need to set an Authorization header to an HTML5 EventSource. As Server Sent Events seems to be disused since Websockets appeared, I cannot find any useful documentation. The approach I have already found is to pass the authorization data within the url... but I don't like this method.

I am using AngularJS and set interceptors on $httpProvider, but the EventSource is not intercepted by AngularJS, so I cannot add any header.

解决方案

EventSource doesn't have an API for sending HTTP headers to server. I was struggling with this problem too when I was building realtime-chat using SSE.

However I think cookies will be sent automatically if your SSE server is the same server as your authentication server.

这篇关于EventSource中的HTTP授权标头(服务器发送事件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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