如何从邮递员的响应头中提取特定的字符串值?

How to extract a particular string value from response header in postman?

我有以下字符串,想提取代码的值。我使用了 split 函数,但它在 postman 中运行良好,但当我在 newman 中执行相同时,它给出了错误。

header1=https://debugger.com/ultradebugcode?code=EgxIZAAU3uHVt20pc9qqpv-xNcAWxitpB0vgMiulNLG2hkysukmjR04Fxxnuz9Yb&state=ABC

我要提取代码的值。在这种情况下是

EgxIZAAU3uHVt20pc9qqpv-xNcAWxitpB0vgMiulNLG2hkysukmjR04Fxxnuz9Yb

我使用的代码是

    var str= pm.response.headers.get('header1');
    var str1= str.split('code=', 2)[1];
    var code= str1.split('&', 2)[0]; // get the code

它在 postman 中运行良好,但为什么 newman 在这里出错?

这对我有用:

let str = pm.response.headers.get("header1").split("code=")[1]

console.log(str.split("&")[0])