![](/img/trans.png)
[英]Error: unexpected end of stream when upload file to server (react native fs)
[英]Axios: unexpected end of stream
我在使用反应原生的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");
});
由于某种原因,如果放在data
参数之后, timeout
参数将不起作用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.