添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

Ask Question

Refactoring my app to use a new price API and I'm getting the following error:

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

The free API doc for /currencies/ticker http://docs.nomics.com/#tag/Currencies

Here is my code after I added '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

Also just tried

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

and lower cased key 'content-type': 'text/event-stream'

Not sure what I'm missing, hoping for some thoughts here...

UPDATE

I am able to get the response back now by removing 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

However I still get the same error

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

What is the outcome of const currencies = await axios.get(api.nomics.com/v1/currencies/…). I tried this and it worked. I guess some other global configuration is affecting/breaking this. – Rayon Aug 29, 2020 at 4:00

Are you using a CORS extension? I had this issue as well and ran across this post: SSE `this.eventSource.onmessage` call fails. Error `"EventSource's response has a MIME type ("application/json") that is not "text/event-stream"

You may need to disable the CORS extension to remove that console error.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.