React-native: Fetch response.text() gives responseData =[Object Blob]

Created on 10 Aug 2019  路  5Comments  路  Source: facebook/react-native

fetch response.text() gives responseData=[Object Blob]

"react-native: 0.60.4
"react": "16.8.6",

Steps To Reproduce

1.react-native init project
2.fetch one request
3.console the response

 function request(url, option) {
        const newOptions = option
        if (newOptions.method === 'POST') {
          newOptions.body = JSON.stringify(newOptions.body)
     }
  return fetch(url, newOptions)
         .then(response => {
          console.log('newOptions', newOptions)
          console.log('response', response)
        return response.text()
    })
    .then(body => {
       console.log('body', body) 
     })

   .catch(e => {
   console.log('e', e)
  })
}
  // get request
    export async function get(url, params) {
       let requrl = stringify(params, { indices: false })
       return request(`${baseUrl}${url}?${requrl}`, {
       method: 'GET',
       headers: {
         Authorization: `Bearer ${token}`,
         'content-type': 'application/json'
      }
    })
  }

console result

    response={
       bodyUsed: true
       headers: Headers
       map: {content-type: "application/vnd.api+json", content-length: "551"}
       __proto__: Object
      ok: true
      status: 200
      statusText: ""
      type: "default"
       url: "https://chain-api.test.com/question/list?"
      _bodyInit: Blob {size: 1177, type: "application/vnd.api+json"}
       _bodyText: "[object Blob]"
    }

body [object Blob]

Bug Ran Commands 馃寪Networking

Most helpful comment

I'm struggling with the same issue. I believe it's related to: https://github.com/facebook/react-native/issues/25701

All 5 comments


Thanks for submitting your issue. Can you take another look at your description and make sure the issue template has been filled in its entirety?

馃憠 Click here if you want to take another look at the Bug Report issue template.

I'm struggling with the same issue. I believe it's related to: https://github.com/facebook/react-native/issues/25701

add the follow in the entry index.js,then it can work

      GLOBAL.XMLHttpRequest = GLOBAL.originalXMLHttpRequest || GLOBAL.XMLHttpRequest
      global.Blob = null

@guaiguaimao Thanks for your reply to fix this issue and it fixed for me for iOS device but it is not working for Android.

@guaiguaimao this fix causes another problems. I have web-sockets in my application and after that when I try to emmit events with object as parameters socket.emit('someEvent', { param }); it throw an error: "TypeError: Right-hand side of 'instanceof' is not an object"

Was this page helpful?
0 / 5 - 0 ratings