react-native: res.body is null, only res.text is working
See original GitHub issueUsing 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:
- Created 8 years ago
- Comments:20 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
same here, if my API return content-type header
application/vnd.profiles+json
instead ofapplication/json
res.body is null and res.text has content.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?