react-native - Axios:流意外结束

标签 react-native axios

我在 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/

相关文章:

javascript - 使用 Axios 下载图像并将其转换为 base64

ajax - 跨域请求被阻止 : The Same Origin Policy disallows reading the remote resource (POST request with object)

css - 在 React Native 中将 View 置于其他 View 之上

objective-c - react native 桥接 : Passing JSON to Swift function

javascript - react-native async 函数返回 promise 但不是我的 json 数据?

javascript - Axios 弃用并发请求?

javascript - 如何根据第二个响应用axios更新第一个响应的内容

react-native - React Native 有哪些错误跟踪服务?

android - 将 native 应用程序转换为 native android 依赖项/库

javascript - 使用带有 map 的 setTimeout 以避免 API 速率限制的问题