简体   繁体   English

如何设置SSE请求授权标头?

[英]How can I set SSE request authorization header?

How can I send authorization header for OAuth2 in SSE in javascript? 如何在javascript中的SSE中发送OAuth2的授权标头? It seems like native JS EventSource does not support any headers to be sent when listening to SSE. 侦听SSE时,本机JS EventSource似乎不支持发送任何标头。 Is there another library maybe that will allow me to do that? 是否有另一个图书馆可以允许我这样做? Does anyone have any idea how to do it? 有谁知道如何做吗?

The SSE standard does not support sending headers (or POST data). SSE标准不支持发送头(或POST数据)。 Only GET data and cookies. 仅获取数据和cookie。 Your choices boil down to: 您的选择归结为:

  • Do a login step first, get a session cookie, and then that cookie will be sent with your EventSource request. 首先执行登录步骤,获取会话cookie,然后将该cookie与您的EventSource请求一起发送。
  • Fall back on using XMLHttpRequest2 , ie comet/longpoll techniques. 退一步使用XMLHttpRequest2 ,即彗星/ longpoll技术。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM