javascript - 如何更改请求超时时间
问题描述
我有一个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));
}
}
解决方案
尝试这个:
@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 {...
推荐阅读
- angular - 防止为任何子组件测试调用父路由 ngOnInit 方法
- bazel - 使用 bazel 在 windows 上构建 abseil
- python - 如何在命令行上传递参数而不在python中使用标志
- php - 在数据库中以字符串格式存储队列条目是否安全?
- regex - 从原始数据中捕获特定格式的日期
- c# - 有没有比使用消息框的方法,因为我正在创建一个 Web 应用程序而不是一个 Web 表单
- javascript - 调用的函数未在 React 中返回结果
- jquery - 使用 Django 的数据表无法从 MySQL 数据库中获取数据
- javascript - 如何检测被其他人脸隐藏的 3d 形状的人脸(从角度不可见)?
- react-native - 找不到参数的方法 implementation() [com.facebook.android:facebook-android-sdk:4.34.0]