接口1:登录接口http://localhost:9091/api/v1/user/login
request body:
{
"authRequest":{
"userName":"user01",
"password":"pwd"
}
}
response body:
{
"access_token": "3b6754f00bb0063071c5b71ce2b56b4ed0ce56a63493e785bea85b74c41ce200",
"code": "200",
"message": "login success"
}
接口2:菜单浏览http://localhost:9091/api/v1/menu/list?type=breakfast
Header: {
Content-Type : application/json,
access_token : [access_token]
}
1、点击:Environment quick look
2、在New Environment中加access_token
3、在登录接口的 Tests 中加上:
//将数据解析成json格式
var data=JSON.parse(responseBody);
//获取access_token值
var access_token=data.access_token;
//设置成环境变量
pm.environment.set("access_token", access_token);
4、运行第一个接口,在New Environment -> CURRENT VALUE 中可以看到token数据
5、在浏览接口中引用变量{{access_token}}