postman token 请求头添加

思路:
1、登录成功后将 得到的token设置为集合变量
2、在需要携带Authorization的请求头上使用该集合变量

postman token 请求头添加_第1张图片

postman token 请求头添加_第2张图片

关键代码




const responseData = pm.response.json();
if(responseData.code == 1) {

    // 获取token
    const {data:{token}} = responseData

    // 设置为集合变量
    pm.collectionVariables.set('admin_token',token);

    //console.log(pm.collectionVariables.get('admin_token'));
}else{
    console.log('请求错误');
}

你可能感兴趣的:(postman,测试工具)