作者:川川shilohjr_993 | 来源:互联网 | 2023-08-27 09:23
首先添加一个环境首先设置环境为:NoEnvi,然后在点击眼睛按钮,会出现add 点击add按钮然后新建一个环境 添加一个变量用来接受接口返回的数据举例:token_tes
首先添加一个环境
首先设置环境为:No Envi,然后在点击眼睛按钮,会出现add
![](https://img.php1.cn/3cd4a/1eebe/cd5/21e585a7e21fc7dc.png)
点击add按钮然后新建一个环境
![](https://img.php1.cn/3cd4a/1eebe/cd5/e88efe5b0a13a7fa.webp)
添加一个变量用来接受接口返回的数据
举例:token_test是登陆接口返回的,需要将其保存到环境变量中,方便后面的接口继续使用
![](https://img.php1.cn/3cd4a/1eebe/cd5/a5d7215df572c386.webp)
在登陆接口编写Tests获取token
点击Tests按钮,输入以下代码
![](https://img.php1.cn/3cd4a/18ace/696/1d8e759bd3e6bbec.jpeg)
pm.environment.set("token_test", 'Bearer '+JSON.parse(responseBody)['row']['auth_token']);
console.log(pm.environment.get("token_test"));
请求登陆接口返回token, 点击眼睛按钮可以看到当前token_test已经有值了
![](https://img.php1.cn/3cd4a/1eebe/cd5/d05d9dfd09a56332.webp)
在接下来的接口中使用{{token_test}}就好了