亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

@Interval中的nestJs httpService.get請求沒有反應

@Interval中的nestJs httpService.get請求沒有反應

慕的地8271018 2023-07-29 13:32:44
我有一個注入了 HttpService 的服務,并使用 @Interval(20000) 啟動請求。在間隔函數中,我使用 this.http.get(...) 向另一臺服務器發出請求,但我沒有看到任何反應,無論是請求還是異常。我只看到控制臺日志“handleInterval”!怎么了? :import {HttpException, HttpService, Injectable} from '@nestjs/common'@Injectable()export class AppService {  constructor(private readonly http: HttpService) {}  @Interval(20000)  handleInterval() {    console.log('handleInterval');    let response = this.http.get('192.168.0.162:8081/diag.fhtml', {responseType: 'arraybuffer'}).pipe(        map(res => {          console.log('received data');          return res.data;        }),        catchError(e => {          console.error(e);          throw new HttpException(e.response.data, e.response.status);        }));  } : :}
查看完整描述

1 回答

?
慕哥6287543

TA貢獻1831條經驗 獲得超10個贊

NestHttpService 使用RxJSObservables。要觸發請求,您需要添加.subscribe() 制作函數async并添加.toPromise()。



查看完整回答
反對 回復 2023-07-29
  • 1 回答
  • 0 關注
  • 190 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號