【发布时间】:2018-01-27 03:58:37
【问题描述】:
我有一个带有按钮的简单 React Native 应用程序。在按下时,它会调用以下发出 POST 请求的函数。 我已经在 POSTMAN 中进行了测试,并且请求有效。但是,我想测试我的应用程序,但无法记录响应或任何错误。只有 'here' 和 'done' 的 console.log 语句正在打印(我在 Chrome 中使用远程调试器看到它们)。
似乎 fetch 函数被忽略了,没有警告/错误/日志。 我在这里做错了什么?或者确保请求有效的最佳方法是什么?
_onPressButton() {
console.log('here');
fetch('http://passport.local/oauth/token', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
client_id: '2',
client_secret: 'value',
grant_type: 'password',
username: 'value',
password: 'value',
})
})
.then((response) => response.json())
.then((responseJson) => {
console.warn(xhr.responseText);
console.log(responseJson);
return responseJson;
})
.catch((error) => {
console.error(error);
});
console.log('done');
}
【问题讨论】:
标签: post logging react-native fetch