【发布时间】:2019-03-29 01:59:09
【问题描述】:
我正在尝试在 NestJS 中发出 Http 请求
因为它的灵感来自 Angular,所以我添加了我的标题
import { Injectable, HttpService} from '@nestjs/common';
...
const headersRequest = new Headers();
headersRequest.append('Content-Type', 'application/json');
headersRequest.append('Authorization', `Basic ${encodeToken}`);
然后调用api
const result = await this.httpService.post(apiUrl, newDevice, { headers: headersRequest });
我收到一个错误
ReferenceError: Headers is not defined
当我使用 Headers 进行导入时
我在 VScode 中收到此消息警告
Only a void function can be called with the 'new' keyword.
【问题讨论】:
标签: javascript angular httprequest nestjs