{
"success": true,
"code": 200,
"data": {
"user": {
"id": 137,
"userName": "admin",
"name": "管理员",
"orgIdList": [54],
"orgName": "测试一",
"roleList": [47, 50]
},
"token": "eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJsaXMiLCJ1c2VySWQiOjEzNywibmFtZSI6Imxpc-euoeeQhuWRmCIsIm9yZ0lkIjo1NCwiZXhwIjoxNjM1NTU4MzM5fQ.iAWY5SgxqH1eNSUOliSFAkSY3NF0lslraEli3rR5GH5U3pJjikpvGgY9tb4IWvwPjKwoE8FEOmtYHNUf6zn4_sYhgmR0O5_xOSkQJqIjlA1flaEZgT39L-BUIzEdrV7NFvQVuEJjT42aZSi_5x-k7ouRAzb5JKHu7MQJ5Ey2pQQ"
}
}
从登录接口截取出token值,然后添加到header中
// 登录,获取token
lr_start_transaction("login");
web_custom_request("token",
"URL=http://**.**.**.**:8080/api/auth/jwt/token",
"Method=OPTIONS",
"Resource=0",
"Referer=",
"Snapshot=t119.inf",
"Mode=HTML",
LAST);
web_set_max_html_param_len("262144"); // 默认最大长度为256
// 获取token解析算法:
web_reg_save_param_ex(
"ParamName=Authorization", // 为获取到的token设置参数名
"LB=\"token\"\:\"", // 匹配token 值左边界
"RB=\"",// 匹配token 值右边界
SEARCH_FILTERS,
"Scope=Body",//匹配范围
"RequestUrl=*/api/auth/jwt/token*",//匹配登录接口
LAST);
web_custom_request("token_2",
"URL=http://**.**.**.**:8080/api/auth/jwt/token",
"Method=POST",
"Resource=0",
"RecContentType=application/json",
"Referer=http://**.**.**.**:8080/",
"Snapshot=t120.inf",
"Mode=HTML",
"EncType=application/json;charset=utf-8",
"Body={\"username\":\"admin\",\"password\":\"admin123\"}",
LAST);
lr_end_transaction("login", LR_AUTO);
// 将解析出的 token 自动添加在请求的头部(request header):
web_add_auto_header("Authorization", "{Authorization}");
//后续请求header自动增加了Authorization参数传递token值
web_custom_request("menu",
"URL=http://**.**.**.**:8080/api/users/137/menu",
"Method=GET",
"Resource=0",
"Referer=",
"Snapshot=t121.inf",
"Mode=HTML",
LAST);