由于部分系统登录需要对密码进行加密,如加密结果是固定的可以使用参数化实现密码,如加密结果是动态的(比如会加时间戳等),则需要动态加密后再拿来用。以下提供一种方式,通过beanshell调用python脚本(当然会写java的人,直接在beanshell里就能直接实现需要的效果)加密进行登录
import java.io.BufferedReader;
import java.io.InputStreamReader;
String thr = "";
thr = vars.getThreadName();
String pystr = "";
pystr = "python" + " H:\\getPasswd.py " ;
Process proc = Runtime.getRuntime().exec(pystr);
proc.waitFor();
BufferedReader b=new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line="";
String[] response = new String[3];
int i=0;
while((line=b.readLine())!=null){
response[i]=line;
System.out.println(i);
System.out.println(response[i]);
i=i+1;
}
vars.put("user",response[0]);
vars.put("password",response[2]);
请求body中使用该参数
{"username":"${user}","password":"${password}","verifyType":[]}