Angular Server Sent Event调用失败,我在 Chrome 开发工具(附图片)中看到this.eventSource.onmessage
一个错误,返回了两个。"EventSource's response has a MIME type ("application/json") that is not "text/event-stream". Aborting the connection."
Content-Type
后端代码:Spring Reactor/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.
任何帮助都会很棒!