本文介紹了SSE`this.ventSource.onMessage`調(diào)用失敗。錯(cuò)誤`事件源的響應(yīng)具有不是文本/事件流的MIME類(lèi)型(應(yīng)用程序/json";)。的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
ANGLE Server Sent事件this.eventSource.onmessage
調(diào)用失敗,錯(cuò)誤"EventSource's response has a MIME type ("application/json") that is not "text/event-stream". Aborting the connection."
我在Chrome Dev工具(附圖)中看到有兩個(gè)Content-Type
被返回。
后端代碼:SpringReader/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
給出錯(cuò)誤EventSource's response has a MIME type ("application/json") that is not "text/event-stream". Aborting the connection.
任何幫助都是最好的!
推薦答案
我使用ASP.Net(和NodeJS)時(shí)遇到了同樣的問(wèn)題。
我不知道這是否有幫助,但我體驗(yàn)到,如果您使用Moesif Origin & CORS Changer(在標(biāo)準(zhǔn)配置中,我沒(méi)有測(cè)試自定義配置),某些標(biāo)頭會(huì)被插件(至少是Content-Type和X-Content-Type-Options)添加或覆蓋(選擇了一個(gè))。
因此,可能是您在Chrome中安裝的某個(gè)插件導(dǎo)致了這一問(wèn)題。嘗試在不同的瀏覽器中運(yùn)行或不使用插件。
希望我能幫助別人,祝你有愉快的一天!
這篇關(guān)于SSE`this.ventSource.onMessage`調(diào)用失敗。錯(cuò)誤`事件源的響應(yīng)具有不是文本/事件流的MIME類(lèi)型(應(yīng)用程序/json";)。的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,