node.js - 使用 NodeJS Loopback 调用其他 API 后如何查看标头?
问题描述
发送请求后,看不到响应的标头
- 在控制器中,我有发送请求的方法:
@get('/getToken')
async getToken(): Promise<any> {
return await this.s4hanapurreqService.getToken(); <- Response Ok
}
- 此方法在服务文件中调用另一个:
界面:
export interface S4hanapurreqService {
getToken(): Promise<any>;
}
- 该接口 S4hanapurreqService 与数据源通信
async value(): Promise<S4hanapurreqService> {
return getService(this.dataSource);
}
数据源:
"operations": [
{
"template": {
"method": "GET",
"url": "https://<some url>",
"headers": {
"x-csrf-token": "fetch"
}
},
"functions": {
"getToken": [] <-- this is my controller method
}
}
一切正常,因为我得到了回应:
控制器:
@get('/getToken')
async getToken(): Promise<any> {
return await this.s4hanapurreqService.getToken(); <- Response Ok
}
json响应:
{
"d": {
"EntitySets": [
... Data ...
]
}
}
但是当我调试时,我发现我只有这个,并且标题看起来不像状态 ,200,201 等
我不能使用这个因为失败:
var token = response.headers['x-crsf-token'];
从我的响应中获取标题的正确代码是什么?
问候。
解决方案
推荐阅读
- prestashop-1.7 - 我正在尝试在 prestashop 中开发一项功能以应用促销
- javascript - Javascript .filter() -> 无法读取 null 的属性“X”
- python - 我得到了“nan”的损失价值,同时遵循了 huggingface 文档中的“Question Answering with SQuAD 2.0”
- javascript - 将文件名传递给 Emscripten 生成的 js 作为参数
- python - 为什么 PDFPlumber 不能与 PysimpleGUI 一起使用?
- python - Tkinter 在多个帧上更改窗口大小
- reactjs - 页面刷新时 React UseContext 丢失数据
- android - 接收方还是服务方?或者两者兼而有之?
- slack-api - 识别我的应用在 Slack 中发布的消息
- c# - 数组排序的方法 Unity C#