【发布时间】:2018-12-06 01:07:54
【问题描述】:
我对使用 fetch 或 axios 库的 react-native ajax 调用有一些问题。无法在失败的 Ajax 调用上获取 http statusText。 statusText 属性始终未定义。
这里有一个简单的例子:
axios.post(this._apiBasePath + url, data, {
headers: this._header,
timeout:5000,
responseType: respType
}).then(d => {
res(d.data);
}).catch(err => {
if(err.response){
console.log(err.response);
// there is a status 401 but no statusText in err Object
}
});
也许你们可以帮助我?
(在 iOS 和 Android 模拟器中测试)
(反应 16.4.1 / 反应原生 0.55.4)
【问题讨论】:
-
用axios,相信可能是err.data.response?
-
数据在 err 对象中为空。我认为它只是在成功案例中填写。
-
err.response.data / err.response.headers / err.response.status?
-
我更新了问题并添加了带有 console.log 输出的屏幕截图
-
如果我直接从浏览器(相同的后端)执行相同的请求,它会返回以下内容(chrome 调试器):状态代码:401 [] 无法验证用户“测试”!原因:未找到用户“asd”。所以有一个返回的statusText
标签: react-native fetch axios