jmeter beanShell modify http request parameters

When using jmeter for testing, it is necessary to encrypt the plaintext parameters of the previous response, such as userName='tom' token='%sdf%sdkdfj' and so on, before proceeding to the next http request,
which involves three problems
1 , Encryption to introduce a custom encryption function
2. To be able to get the first http response
3. Before the second http request, dynamically build parameters

1. Introduce encryption functions and fastjson


2. Take the last request in beanShell The response is added
in the first request, the post-processor
builds a BeanShell Post Processor
  import com.alibaba.fastjson.JSON;
  import com.alibaba.fastjson.JSONObject;

// get the response value
  String json = prev.getResponseDataAsString();  
    log.info("json="+json);  

 JSONObject obj = JSON.parseObject(json);

	String dlapp = obj.getString("dlapp");
     log.info("dlapp="+dlapp);  
     
     String ret = obj.getString("ret");
     log.info("ret="+ret);

       
     String capFlag = obj.getString("capFlag");
     log.info("capFlag="+capFlag);

    
    // put it in a variable after parsing  
    vars.put("dlapp",dlapp);
    vars.put("capFlag",capFlag);  
    vars.put("ret",ret);  



3. Before the second http request, the parameters must be dynamically constructed. For

the second http request, the parameter value of the request uses the jmeter variable
such as
sign=${sign}

Add, preprocessor
Build a BeanShell PreProcessor
to call the encryption function to encrypt and put it into a variable
    String capFlag = vars.get("capFlag");  
    String dlapp= vars.get("dlapp");  
    String ret= vars.get("ret");  

    log.info("dlapp="+dlapp);  
    log.info("capFlag="+capFlag);
    log.info("ret="+ret);  

   	vars.put("dlapp",dlapp);
    vars.put("capFlag",capFlag);  
    vars.put("ret",ret);   


View jmeter log log




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326398542&siteId=291194637