【问题标题】:how to change the request timeout time如何更改请求超时时间
【发布时间】:2021-01-14 22:04:56
【问题描述】:

我有一个API,在开发环境中需要超过1 minute才能返回,但是,60s总是超时,我该如何更改timeout默认值(postman,它正常返回,即使它需要超过 1 分钟,所以它不是后端)? 我尝试了我在互联网上找到的一个解决方案,但是,它的值小于 60s 它可以工作,但是即使设置一个很高的值,当它达到60s 时也会超时。

@Injectable()
export class TimeoutInterceptor implements HttpInterceptor {
  constructor(@Inject(DEFAULT_TIMEOUT) protected defaultTimeout: number) {
  }

  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    return next.handle(req).pipe(timeout(300000));
  }
}

【问题讨论】:

  • 不能放:setTimeout(function(){ alert("Hello"); }, 3000);
  • @Fiehra 我不明白

标签: javascript angular nativescript nativescript-angular


【解决方案1】:

试试这个:

@NgMoule({
....
   imports: [HttpClientModule],
   providers: [{provide: DEFAULT_TIMEOUT, useValue: 180*1000}] <- should be provided in the same module where you already have HttpClientModule
})
export class AppModule {...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-18
    • 2018-08-28
    • 1970-01-01
    • 2011-02-04
    • 1970-01-01
    • 1970-01-01
    • 2011-02-26
    相关资源
    最近更新 更多