2017-10-13 32 views
1

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

我怎樣才能防止這種情況發生?

回答

0

的問題實際上是由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

1

我曾與甲骨文,長時間請求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'))) 
}}