繁体   English   中英

Axios:流意外结束

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM