![](/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.