【发布时间】:2021-05-24 13:43:34
【问题描述】:
您好,我尝试使用nestJs 框架来构建一个简单的应用程序。 此应用程序调用 http 服务来检索和记录一些信息。我附上nestjs服务的代码:
import { HttpService, Injectable, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { UserInformation } from 'src/models/userInformation';
import https from 'https';
@Injectable()
export class CallService {
private authRequest: any;
private httpsAgent: https.Agent;
constructor(
private configService: ConfigService,
private httpService: HttpService,
) {
this.httpsAgent = new https.Agent({
rejectUnauthorized: false,
});
this.authRequest = {
username: configService.get('username'),
password: configService.get('password'),
};
}
getUserInformation(): Promise<UserInformation> {
var url = this.configService.get('apiEndpoint') + 'scrapt/getUserInfo';
return this.httpService
.get(url, {
auth: this.authRequest,
httpsAgent: this.httpsAgent,
})
.toPromise()
.then((response) => {
return new UserInformation(response.data);
});
}
}
当
获取用户信息
function is trigger in console 出现这个错误:
'无法读取未定义的属性'Agent''
它是在线参考:
this.httpsAgent = new https.Agent({
我试图在互联网上搜索一些信息,但我没有找到任何东西,我们知道如何解决它吗?
【问题讨论】:
-
nest 无法解析此
https.Agent类型的值。我认为阅读custom providers 或使用http module 会有所帮助。