簡體   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