我有一个发送测试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 以对其进行测试),并根据 Wiresharkevent: data
发送了内容,但既不调用onmessage
也不onerror
调用处理程序。onerror
当我停止服务器时调用。
网络事物的响应选项卡中从未显示任何数据。
有谁知道出了什么问题?