question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react-native: res.body is null, only res.text is working

See original GitHub issue

Using react-native 0.4.1, both my request.get and request.post methods are working, but the res.body is undefined, forcing me to manually JSON.parse the res.text:

request
      .post('http://10.0.0.3:9091/auth')
      .type('json')
      .send({
        email: 'xxx',
        password: 'xxx',
      })
      .end((error, res) => {
        if (res.status === 200) {
          console.log(res.body); // undefined
          var token = JSON.parse(res.text).token; // working
...

When calling this from regular React, it’s working perfectly.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:20 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
MathieuDoyoncommented, Mar 20, 2016

same here, if my API return content-type header application/vnd.profiles+json instead of application/json res.body is null and res.text has content.

0reactions
NICK-DUANcommented, Sep 18, 2018

i have a problem probably like this。 Http.post('/auth_manage/auth/change_auth/') .send({name: values.name}) .send({op: this.state.value}) .set({'X-CSRFToken': Cookie.getItem('csrftoken')}) .type('application/x-www-form-urlencoded') .end((err, res) => { console.log(res) }) this is my code, when i use console.log print res, i got a html file which is my static file, i don’t know why, anybody can help me?

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-native: res.body is null, only res.text is working · Issue #636
Using react-native 0.4.1, both my request.get and request.post methods are working, but the res.body is undefined, forcing me to manually JSON.
Read more >
fetch gives an empty response body - Stack Overflow
I just ran into this. As mentioned in this answer, using mode: "no-cors" will give you an opaque response , which doesn't seem...
Read more >
Handling a Null Response from an API
I've been working with React Native lately, which uses the Fetch API for asynchronously fetching data from web services.
Read more >
[Solved]-how to read the body of a response-React Native
Coding example for the question how to read the body of a response-React Native. ... bodyUsed && response.body != null) { if (isNaN(response.body)) ......
Read more >
Notifications - Expo Documentation
submitButtonTitle : (iOS only) A string which will be used as the title for the button used for submitting the text response. placeholder...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found