【问题标题】:How to handle long time request in Angular 4?如何在 Angular 4 中处理长时间请求?
【发布时间】:2017-10-13 13:23:00
【问题描述】:

我有一个请求,在 Angular 4 中,这需要很长时间。 后端位于连接到 Oracle 数据库的 .Net Core 2.0 中。它应该等待一个长查询在数据库中运行以获取数据并将其发送到客户端。但是,似乎客户端无法等到进程结束(所有记录的返回),我得到的是错误:

加载资源失败:服务器响应状态为 502 (坏网关)

当 CGI 应用程序未返回有效集合时会发生此错误 HTTP 标头,或者当代理或网关无法发送 请求到父网关。您可能需要获取网络跟踪或 如果不是 CGI 问题,请联系代理服务器管理员。

这不是超时错误,就像我想的那样。 这是我的请求代码:

exportExcel(dadosConsulta: DadosConsultaModel) : Promise<any>{
      let url ="/api/Relatorios/exportToExcel";      
      return this.http
      .post(url, JSON.stringify(dadosConsulta),{ headers: this.headers })
      .timeout(500000)
      .toPromise()
      .then(data => data.json())
      .catch(this.handleError);
  }

我怎样才能防止这种情况发生?

【问题讨论】:

    标签: c# asp.net angular post asp.net-core


    【解决方案1】:

    我使用过 oracle、长时间的请求查询和 observables,没有遇到这个问题。

    类似的东西

    login(account: string, password: string, user: string): Observable <any> {
    
    let body = new URLSearchParams();
    
    body.set('account', account);
    body.set('password', password);
    body.set('user', user);
    
        return this.http.post(this.globalVars.apiUrl + 'login', body)
            .map((res: any) => {
                let result = res.json().data.result;
                let data = res.json().data;
                this.client.auth = {
                    authCode: result.authCode,
                    token: result.token,
                };
                this.firstLogin = data.firstLogin;
                return this.client;
            })
            .catch((error: any) => {
                console.log('error', error._body);                                
                return Observable.throw(error._body);                
            })
            .timeoutWith(25000, Observable.throw(new Error('Connection Error')))
    }}
    

    【讨论】:

      【解决方案2】:

      问题实际上来自 IIS,为了解决这个问题,我必须在我的项目中添加一个 web.config(默认情况下没有创建)并像这样修改“aspNetCore”标签:

      <aspNetCore **requestTimeout="00:20:00"**  processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
      

      从这篇文章中得到它:Timeouts with long running ASP.NET MVC Core Controller HTTPPost Method

      【讨论】:

        猜你喜欢
        • 2020-10-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-02-05
        • 2021-02-07
        • 2010-12-13
        • 1970-01-01
        相关资源
        最近更新 更多