如何处理Angular 4中的长时间请求?

问题描述:

我在Angular 4中提出了一个需求非常长的请求。 后端位于连接到Oracle数据库的.Net Core 2.0中。它应该等待长时间的查询才能在数据库中运行以获取数据并将其发送到客户端。然而,似乎客户端是无法等待的过程(所有记录返回)结束时,我得到的是错误:如何处理Angular 4中的长时间请求?

Failed to load resource: the server responded with a status of 502 (Bad Gateway)

This error occurs when a CGI application does not return a valid set of HTTP headers, or when a proxy or gateway was unable to send the request to a parent gateway. You may need to get a network trace or contact the proxy server administrator, if it is not a CGI problem.

这不是一个超时错误,因为我以为这是的。 这里是我的请求的代码:

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); 
    } 

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

的问题实际上是由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

我曾与甲骨文,长时间请求querys和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'))) 
}}