我尝试使用下列代码获取请求结果,但获得了一个y意外的结果:
import { Injectable } from '@nestjs/common';
import { HttpService } from '@nestjs/axios';
@Injectable()
export class RecaptchaService {
constructor(private httpService: HttpService) {}
verifyResponse(reCAPTCHAToken: string, clientIp: string): number {
const checkResult = this.httpService.post(
'https://www.recaptcha.net/recaptcha/api/siteverify',
{
secret: 'AAAA',
response: reCAPTCHAToken,
remote: clientIp,
},
);
console.log(checkResult);
return 0.2;
}
}
结果:
Observable {
source: Observable { _subscribe: [Function (anonymous)] },
operator: [Function (anonymous)]
}
十分感谢前面两位回答所提供的思路,问题已解决。Nestjs封装的Axios会返回一个Observables对象,查阅Rxjs文档后,使用以下代码有效解决了问题和需求: