1

我正在编写以下预请求脚本来获取我的 JWT 进行身份验证:

pm.sendRequest(echoPostRequest, function (err, res) {
    console.log(err, res, typeof res);
    if(err === null){
        console.log(res.header)
        // var authHeader = res.header.find(v => {v.key === 'Authorization'})
    }
});

这是控制台输出当前的样子:

null, {id: "4ba2b741-316e-454d-b896-eab3aef74ae2", status: "OK", code: 200…}, object
undefined 
OK

// If you enlarge the opbject it looks like the following:

id: "4ba2b741-316e-454d-b896-eab3aef74ae2"
status: "OK"
code: 200
header: [10] <--- There are my headers ?!
stream: {…}
cookie: [0]
responseTime: 121
responseSize: 0

问题是我无法访问header脚本总是告诉我的数组undefined,如果我尝试访问cookie数组也是如此。但我可以访问所有其他单个属性,也许是因为headercookie是数组?我不知道。任何想法我做错了什么以及如何获得我的Authorization标题?

4

1 回答 1

1

我认为问题一定是一个错误,我的解决方法是将对象字符串化并解析为 json,而不是可以访问标题。

r = JSON.parse(JSON.stringify(res))
于 2019-12-09T08:54:40.017 回答