我有一个 Angular 5 Node 应用程序。我正在向 Node 服务器发送请求并等待回复。有时服务器会在 5-6 分钟后发送响应。但是在等待响应4 分钟后,http 方法会抛出一个ERR_EMPTY_RESPONSE错误。
我尝试将 timeout() 与该方法一起使用。但是 4 分钟后它仍然会抛出错误。
有没有办法让http方法等待更长时间或者避免这个错误?
const body = JSON.stringify(params);
const headers = new HttpHeaders({'Content-Type': 'application/json'});
return this.http.post('/api/execute', body, {headers: headers})
.map((response) => response)
.catch((error) => Observable.throw(error));
最佳答案
尝试设置 Keep-Alive header
const headers = new HttpHeaders({'Content-Type': 'application/json', 'Keep-Alive': 'timeout=560'});
关于javascript - http 请求在 4 分钟后抛出 ERR_EMPTY_RESPONSE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49752966/