【发布时间】:2022-01-15 17:26:59
【问题描述】:
我有一个 HtppInterceptor,可以在我的应用程序中启动和停止进度条。这通常适用于大多数 Http 请求,但我有许多 api 调用,当这些调用发生时,HttpHandler 永远不会完成,所以进度条不会停止。我添加了几个日志点以查看哪些调用未完成:
intercept(
req: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
console.log('loading', req.url, this.handleRequestsAutomatically);
// If the Auto mode is turned off, do nothing
if (!this.handleRequestsAutomatically) {
return next.handle(req);
}
this._setLoadingStatus(true, req.url);
return next.handle(req).pipe(
finalize(() => {
console.log('Finished Loading', req.url);
this._setLoadingStatus(false, req.url);
})
);
}
Api 调用创建以下请求:
:authority: localhost:5001
:method: GET
:path: /api/Appointments/ej?appointmentGroupId=1&year=2022&month=1&day=14
:scheme: https
accept: application/json
accept-encoding: gzip, deflate, br
accept-language: en-AU,en-GB;q=0.9,en-US;q=0.8,en;q=0.7
authorization: Bearer <token>
dnt: 1
origin: http://localhost:4200
referer: http://localhost:4200/
sec-ch-ua: " Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: cross-site
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/97.0.4692.71 Safari/537.36
我最初认为 api 调用必须保持某种连接打开,但我看不到会发生这种情况,并且标头请求中没有“keep-alive”。 api调用正确返回数据,我看不到连接在两端保持打开状态。
为什么 HttpClient 调用没有完成并停止我的进度条?
【问题讨论】:
标签: angular typescript angular-httpclient angular-http-interceptors