接口A为获取token(无body内容){{URL}}/token?username=123&password=456
返回内容:
{"code": 200,
"msg": "请求成功",
"data": {"access_token": "e58fb844-7835-4b3f-a6c8-8425644bfabe",
"token_type": "bearer",
"refresh_token": "ab64e6c8-05ed-4215-a648-c8d6bad7f5f0",
"expires_in": 86373,
"scope": "read write"}}
B接口预执行A接口获取到token设置为变量,后添加请求头把变量添加到header内
现在需要执行第二遍才可以正确添加到header内,第一遍执行header内直接是变量名称
第一种方法:新建A接口,在A接口的后预执行脚本中使用全局/环境变量获取token:apt.globals.set("access_token", response.json.data.access_token);apt.variables.set("access_token", response.json.data.access_token);在B接口的header中直接引用
第二种方法:直接在B接口中发送一个请求,请求的地址为a接口
apt.sendRequest("http://{{URL}}/token?username=123&password=456", function (response) {
apt.variables.set("access_token", response.json.data.access_token);
});在直接到header中引用
您还有疑问可以直接QQ联系客服,QQ:2184785786