gpt4 book ai didi

javascript - React App : EventSource's response has a MIME type ("application/json") that is not "text/event-stream". 中止连接

转载 作者:行者123 更新时间:2023-12-05 01:10:56 28 4
gpt4 key购买 nike

重构我的应用以使用新的价格 API,我收到以下错误:

EventSource's response has a MIME type ("application/json") that is not "text/event-stream". Aborting the connection.

/currencies/ticker 的免费 API 文档 http://docs.nomics.com/#tag/Currencies

这是我添加后的代码 'Content-type': 'text/event-stream'

const headers: IHeaders = {
baseURL: NOMICS_API_BASE_URL, // 'https://api.nomics.com/v1/'
headers: {
'Content-Type': 'text/event-stream'
},
params: {
key: NOMICS_KEY
}
}

// * GET Currencies
export const getCurrenciesRequest = async () => {
console.log('getCurrenciesRequest...')
const nomics = axios.create(headers)

try {
const currencies = await nomics.get(`currencies/ticker&ids=BTC,ETH,XRP&interval=1d,30d&convert=USD`)
console.log('currencies', currencies)
return currencies
} catch (err) {
return err
}
}

也试过了

const currencies = await axios.get(`https://api.nomics.com/v1/currencies/ticker?key=demo-26240835858194712a4f8cc0dc635c7a&ids=BTC,ETH,XRP&interval=1d,30d&convert=USD`)

和小写键'content-type': 'text/event-stream'

不知道我错过了什么,希望在这里有一些想法......

更新

我现在可以通过删除 axios.create(headers)

来获取响应
export const getCurrenciesRequest = async () => {
console.log('getCurrenciesRequest...')

try {
const currencies = await axios.get(`https://api.nomics.com/v1/currencies/ticker?key=demo-26240835858194712a4f8cc0dc635c7a&ids=BTC,ETH,XRP&interval=1d,30d&convert=USD`)
console.log('currencies', currencies)
return currencies
} catch (err) {
return err
}
}

但是我仍然遇到同样的错误

EventSource's response has a MIME type ("application/json") that is not "text/event-stream". Aborting the connection.

enter image description here

最佳答案

您使用的是 CORS 扩展程序吗?我也遇到了这个问题并遇到了这篇文章:SSE `this.eventSource.onmessage` call fails. Error `"EventSource's response has a MIME type ("application/json") that is not "text/event-stream"

您可能需要禁用 CORS 扩展来消除该控制台错误。

关于javascript - React App : EventSource's response has a MIME type ("application/json") that is not "text/event-stream". 中止连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63643245/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com