gpt4 book ai didi

javascript - 他们在评估预请求脚本时出错 : Cannot read property 'get' of undefined

转载 作者:行者123 更新时间:2023-12-01 01:37:57 27 4
gpt4 key购买 nike

我正在尝试通过预请求脚本在 Postman 中访问我的 POST 请求的响应。

脚本如下:

var mobiles = postman.environment.get("mobiles");

if (!mobiles)
{
mobiles =["8824444866","8058506668"];
}

var currentMobile = mobiles.shift();
postman.environement.set("mobile","currentMobile");
postman.environement.set("mobiles",mobiles);

当我单击“发送”按钮时, postman 中显示错误,如下所示:

Their was an error in evaluation the Pre-request Script: Cannot read property 'get' of undefined.

请提出一些解决方案

最佳答案

您正在尝试/寻找的是 postman.setEnvironmentVariable(key, value) 并且您可以使用新的 pm.environment.set(key, value) code> 当然,它是同一功能的简写。

有权访问环境 API 的是 pm,而不是 postman。另外,你的脚本中有一个错字。它是环境,而您在脚本中设置变量的环境

这是固定脚本:

注意:这仅适用于 native 应用

var mobiles = pm.environment.get("mobiles");

if (!mobiles)
{
mobiles =["8824444866","8058506668"];
}

var currentMobile = mobiles.shift();
pm.environment.set("mobile", currentMobile);
pm.environment.set("mobiles", mobiles);

如果您想使用 postman.* API,则脚本如下:

适用于 Chrome 应用和 native 应用(旧版支持)

var mobiles = postman.getEnvironmentVariable("mobiles");

if (!mobiles)
{
mobiles =["8824444866","8058506668"];
}

var currentMobile = mobiles.shift();
postman.setEnvironmentVariable("mobile", currentMobile);
postman.setEnvironmentVariable("mobiles", mobiles);

关于javascript - 他们在评估预请求脚本时出错 : Cannot read property 'get' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52665055/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com