我在 React Native 中使用 axios 获取大量数据(JSON)时收到以下错误。
错误:流意外结束
这是我的代码:
axios.post('http://192.168.0.1:5000/download', {
access: data.tokens
})
.then(function (response) {
alert(response.data);
})
.catch(function (error) {
alert("There was an error in communicating to server");
});
我尝试限制 REST API 返回的结果(100 行),但它返回了一些数据。
如何在 Axios 中获取大量数据?
最佳答案
原来axios请求的默认超时设置为0。我通过在axios配置中添加timeout
解决了这个问题。
axios({
method: 'post',
timeout: 1000,
url: 'http://192.168.0.1:5000/download',
data: {
access: data.token
}
})
.then(function (response) {
alert(response.data);
})
.catch(function (error) {
alert("There was an error in communicating to server");
});
出于某种原因,如果将 timeout
参数放在 data
参数后面,则该参数将不起作用
关于react-native - Axios:流意外结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56659365/