this.eventSource.onmessage服务器发送的事件"EventSource's response has a MIME type ("application/json") that is not "text/event-stream". Aborting the connection."调用失败,我在Chrome (图像附件)中看到返回两个Content-Type的错误。

后端代码:弹簧反应堆/REST
@GetMapping(value="/events",produces = "text/event-stream;charset=UTF-8")
public Flux<ConsumerEvent> getProductEvents(){
return kafkaService.getReceiverRecordAllFlux()
.map(record->
new ConsumerEvent(record.topic(),record.value())
);
}
}前端:角
public startKafkaTopicInfoEventSource(): void {
let url = BASE_URL;
this.eventSource = new EventSource(url);
this.eventSource.onmessage = (event) => {//Error: EventSource's response has a MIME type ("application/json") that is not "text/event-stream". Aborting the connection
this.zone.run(() => {
// some code here
})
}
// other code here
}方法this.eventSource.onmessage给出了一个错误EventSource's response has a MIME type ("application/json") that is not "text/event-stream". Aborting the connection.
任何帮助都会很好!
发布于 2021-03-10 11:22:45
我在使用ASP.NET (和nodeJS)时也遇到了同样的问题。
我不知道这是否有帮助,但我经历过,如果您使用Moesif源& CORS变送器 (在标准配置中,我没有测试自定义的),一些标头会被插件(至少是内容类型和X内容类型选项)添加或覆盖(“新的”标题被选中),就像我们在Dev工具屏幕中看到的那样。
所以可能是你在Chrome上安装的插件造成了这种情况。尝试在不同的浏览器或没有插件的情况下运行。
希望我能帮助别人,祝你一天愉快!
https://stackoverflow.com/questions/61546705
复制相似问题