增加Angular 2+和ASP.NET Core WebAPI应用程序中的超时

编程入门 行业动态 更新时间:2024-10-24 08:31:37
本文介绍了增加Angular 2+和ASP.NET Core WebAPI应用程序中的超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的Angular 2+/ASP.NET Core MVC WebAPI应用程序中,我从客户端UI到服务器进行了长时间运行的API调用. 30秒后,请求超时.我想为此客户端或服务器端的特定API调用定义超时.

In my Angular 2+ / ASP.NET Core MVC WebAPI application I have a long running API-call from the client UI to the server. The request times out after 30 seconds. I would like to define the timeout for this specific API call either client- or server-side.

我只找到了全局配置服务器超时的方法,这不是我想要的,因为30秒的超时对于其他呼叫来说是可以的.我还发现了通过传递RxJS的timeout运算符来减少超时客户端的解决方案.但是,据我了解,这不适合 增加超时时间吗?

I have only found ways to configure the server timeout globally, which is not what I want, as the 30 second timeout is fine for other calls. I've also found solutions to decrease the timeout client side by piping RxJS's timeout operator. However, as I understand, this is not suitable for increasing the timeout?

如何设置此特定请求的超时时间? 30秒默认值是从哪里来的?

How can I set the timeout on this specific request? Where does the 30 second default come from?

(该代码实际上并不重要,因为它是标准的API控制器和标准的Angular HTTP调用):

(The code doesn't actually matter, as it is a standard API controller and a standard Angular HTTP call):

this.http.get('api/xyz').subscribe(d => { ... });

推荐答案

要解决超时问题,您可以使用如下所示的RxJ中的timeout

To solve the timeout issue you can use the timeout from RxJs like below

向timeout运算符

这里我要传递60秒的超时时间,因此60秒后如果服务器没有响应,则会抛出超时错误.

Here I am passing 60 seconds as timeout, so after 60 seconds if there is no response from the server then it will throw timeout error.

import ‘rxjs/add/operator/timeout’; ... this.http.get('api/xyz').timeout(60000).subscribe(d => { ... });

更多推荐

增加Angular 2+和ASP.NET Core WebAPI应用程序中的超时

本文发布于:2023-11-15 16:36:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1596145.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   ASP   Angular   NET   WebAPI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!