重构我的应用程序以使用新价格的API,我得到以下错误:
EventSource的响应具有不是“文本/事件流”的MIME类型(“application/json”)。正在中止连接。
免费的API文档
/currencies/ticker
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的响应具有不是“文本/事件流”的MIME类型(“application/json”)。正在中止连接。