我有一个 API,可以执行可能需要长时间运行的任务,最多可能需要 10 分钟。当我从 Postman 调用 API 时,效果很好,但是当我从浏览器(Chrome、Safari、Firefox)使用 API 时,请求在收到响应之前超时。
API是用NodeJS/Express编写的,我已经增加了服务器的超时时间。我还增加了用于进行 API 调用(请求-承诺)的 JavaScript 库的超时。即使请求在浏览器中超时,API 也会继续运行并完成。如何阻止浏览器请求超时?
这些可能会有所帮助:
const xhr = new XMLHttpRequest();
// Set to 0 (which is default) to disable timeout
xhr.timeout = 5000; // Milliseconds
$.ajax({
url: '/some/path',
timeout:5000 // Milliseconds
})
const options = { timeout: 5000 /* Milliseconds */ };
const request = http.request(options, response => {
// ...
});
似乎不支持任何指定超时的方式。