每当我的请求花了2分钟以上的时间,我就会收到确切的消息。浏览器将断开与请求的连接,但后端的请求将继续进行直到完成为止。服务器(在我的情况下为ASP.NET Web API)无法检测到断开连接。
经过一整天的搜索,我终于找到了这个答案,并解释说,如果您使用代理配置,则默认超时为120秒(或2分钟)。
因此,您可以编辑代理配置并将其设置为所需的任何值:
{
  "/api": {
    "target": "http://localhost:3000",
    "secure": false,
    "timeout": 6000000
  }
}
现在,我正在使用agentkeepalive 使其与NTLM身份验证一起使用,并且不知道代理的超时与代理的超时无关,因此必须同时设置两者。我花了一段时间才意识到这一点,所以这里有一个例子:
const Agent = require('agentkeepalive');
module.exports = {
    '/api/': {
        target: 'http://localhost:3000',
        secure: false,
        timeout: 6000000,          // <-- this is needed as well
        agent: new Agent({
            maxSockets: 100,
            keepAlive: true,
            maxFreeSockets: 10,
            keepAliveMsecs: 100000,
            timeout: 6000000,      // <-- this is for the agentkeepalive
            freeSocketTimeout: 90000
        }),
        onProxyRes: proxyRes => {
            let key = 'www-authenticate';
            proxyRes.headers[key] = proxyRes.headers[key] &&
                proxyRes.headers[key].split(',');
        }
    }
};
               
              
err对象-不仅是message