React-native: Problem sending log - console.error

对着背影说爱祢 提交于 2021-01-28 00:15:54

问题


I'm working with Expo React native, I'm trying to send POST request to my express server using axios

App.js - in my React

Axios({
   url:'http://172.20.1.19:3001/api/tracking/locator',
   method:'POST',
   data:{
      test:'wew'
   },
   config:'JSON',
   headers:{
     "Access-Control-Allow-Origin": "*"
   }
})
.then(res=>{
   console.log(res)
})
.catch(err=>{
   console.log(err)
})

In node status its 200, but when console.log the response it throws an error

console.error. "There was a problem sending log message to your development environment",

Tracking.js - Express

var express = require('express');
var cors = require('cors');
var router = express.Router()
const app = express();


const db = require('../models');

app.use(cors({origin:'http://172.20.1.19:19001'}));


router.get('/', function(req, res, next){ 
    res.json({
        data: {
            test :'wew'
        }
    })
})


router.post('/locator', function(req,res,next){
    res.json({
        data:{
            status:'pano mo nasabe'
        }
    })
})


module.exports = router

回答1:


Try to use:

(this helped me)

console.log(JSON.stringify(response.data))  

or

console.log(response.data)

also

console.log(JSON.stringify(response))  


来源:https://stackoverflow.com/questions/54174761/react-native-problem-sending-log-console-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!