jmeter中获取到token,又因为现在都是JWT的所以需要添加Bearer 和获取到的token进行拼接
怎么获取token?
方法一:添加beanshell后置处理器
String response = prev.getResponseDataAsString(); String code = prev.getResponseCode(); String Str="success"; if (!code.equals("200")){ log.info("Respnse is " + response); log.info(code); }else if(response.contains(Str)==false){ log.error("Responsestr is"+response); } log.info(vars.get("token")); vars.put("token","Bearer "+ vars.get("token")); log.info(vars.get("token"));
#上面是获取token
#这里是把token保存在文件 FileWriter fstream = new FileWriter("/home/tarzan/code/data/token.csv",true); BufferedWriter out = new BufferedWriter(fstream); out.write(vars.get("token")); out.write(System.getProperty("line.separator")); out.close(); fstream.close();
方法二:json提取器
Json path expressions:就是你的响应体中 row 值中的token值
例如:{'code':200,row:['token':'XXXXXXXXXXXXX']}