Postman sets the user token as a global variable

1. Create a new user login interface, and return token after the interface request is successful

  1. Create a new login request, and view the response result after the request is successful

  1. Create a new Globals global variable

3. Add javasc code under Tests of the login interface request to set global variables

code show as below:

//设置用户登录的token 为全局变量;
// 首先需要先新建一个Global 全局变量
var jsonData = JSON.parse(responseBody);
postman.setGlobalVariable("zwzc_token", jsonData.result.token);
//这里的jsonData. 后面的路径result.token  根据你们具体的接口返回的body体的路径层级来调整

The things that need to be paid attention to above have been explained in the comments, just pay attention to the adjustment

After the adjustment is completed, just re-initiate the request, and the newly added token will be automatically filled in the global variable

2. Call token to complete other interface requests

1. New interface, application variable token { {zwzc_token}} in the header

Guess you like

Origin blog.csdn.net/weixin_55944621/article/details/128835036