什么是axios默认超时时间

Arr*_*Raj 22 axios

我在文档步骤中找到了设置超时值的方法。

const instance = axios.create({
  baseURL: 'https://some-domain.com/api/',
  timeout: 1000,
  headers: {'X-Custom-Header': 'foobar'}
});
Run Code Online (Sandbox Code Playgroud)

但是我在 axios 官方文档中找不到默认值 - https://github.com/axios/axios

默认超时时间是多少?

此外,在 AXIOS 下面使用 http 服务器/客户端(https://nodejs.org/api/http.html#http_class_http_clientrequest

它是否使用 http 默认超时?我看到我的程序在 2 分钟后超时。

Chr*_*isG 29

根据自述文件,它是 0 表示没有超时

//timeout指定请求超时前的毫秒数。

// 如果请求时间超过timeout,则请求将被中止。超时:1000,

// 默认为0(无超时)

https://github.com/axios/axios/blob/master/README.md#request-config

  • @ArrRaj所以这里可能会发生多种事情。听起来您是在节点环境内而不是在网页上发出此请求。在这种情况下,`axios`仍然没有提供超时(https://github.com/axios/axios/blob/master/lib/adapters/http.js#L248)。但是,很可能存在服务器端超时设置为 2 分钟的情况。你很可能会碰到这个。https://nodejs.org/api/http.html#http_server_timeout (4认同)
  • 谢谢克里斯。所以,axios默认值是0。(更新的问题)但它下面使用http服务器/客户端(https://nodejs.org/api/http.html#http_class_http_clientrequest)它使用http默认超时吗?我看到我的程序在 2 分钟后超时。 (3认同)