Http Firefox中未接收到EventSource消息
我有一个服务器,它发送一条测试Http Firefox中未接收到EventSource消息,http,firefox,eventsource,Http,Firefox,Eventsource,我有一个服务器,它发送一条测试EventSource消息,如下所示: 请求: GET /web/stream/status HTTP/1.1 Host: localhost:1010 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0 Accept: text/event-stream Accept-Language: en-GB,en;q=0.5 Accept-Encoding
EventSource
消息,如下所示:
请求:
GET /web/stream/status HTTP/1.1
Host: localhost:1010
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0
Accept: text/event-stream
Accept-Language: en-GB,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://localhost:1010/web/
Cookie: JSESSIONID=1miz08s4nu74q11sm7y44uwu2b
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
答复:
HTTP/1.1 200 OK
Content-Type: text/event-stream;charset=UTF-8
Connection: close
Server: Jetty(9.0.6.v20130930)
event: data
data: hello
所有行都以\r\n
终止。所以这对我来说是正确的,但如果我在Firefox中尝试这个
var source = new EventSource('/web/stream/status');
source.onmessage = function(event) { console.log(event); };
source.onerror = function(event) { console.log(event); };
。。。然后,它完全按照上述方式连接并执行请求(事实上,我将会话从Wireshark复制到telnet中进行测试),并根据Wireshark发送事件:data
内容,但既不调用onmessage
也不调用onerror
处理程序<当我停止服务器时,会调用code>onerror
网络设备的响应选项卡中从未显示任何数据
有人知道怎么回事吗?啊哈,我找到答案了!Firefox不喜欢
;字符集=UTF-8
。说明书上说你可以有;charset=utf-8
这是Firefox允许的
对规范的解释相当严格,但足够公平
此外,对于单独的数据:
行,只能获得onmessage()
。如果数据:
前面有和事件:
name,则不会调用onmessage()
,而是必须使用以下命令:
source.addEventListener('name_of_my_event', myEventHandler, false);