下面写的是获取response中的token值写入excel中 1、要获取的http请求的response内容为:
2、选中要获取response内容的http请求,点击鼠标右键,选择【添加】-【后置处理器】-【BeanShell PostProcessor】 3、在jmeter的安装目录下的【lib】目录中放入fastjson-1.2.47.jar 4、在【BeanShell PostProcessor】中写入以下内容
import com.alibaba.fastjson.JSONObject; //备注:BeanShell PostProcessor中代码如下: //JMeter的内置API:prev.getResponseData()获取请求的响应内容 byte[] responseData = prev.getResponseData(); //①仅以文件名作为filepath的值,则导出的文件会默认保存在Jmeter安装路径的bin(即JVM的启动路径); //private String filePath = "${ExportExcelName}"; //②指定绝对路径 private String filePath = "C:/Users/admin/Desktop/jmeterTest/xx.csv"; //存放response内容的csv路径 BufferedOutputStream bos = null; FileOutputStream fos = null; File file = null; JSONObject json =JSONObject.parseObject(new String(responseData)); String token_=json.getJSONObject("data").getString("token")+","; BufferedWriter out = null; try { out = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(filePath, true))); out.write(token_+"\r\n"); } catch (Exception e) { e.printStackTrace(); } finally { try { out.close(); } catch (IOException e) { e.printStackTrace(); } }4、运行该http请求的线程组,生成的xx.csv如下: