step:
- Open Fiddler packet capture function
- Download the file in the platform to be tested
- View download-related data captured by Fiddler, and view the incoming parameters
- Create a Jmeter HTTP request and pass in the above parameters.
- Create a regular extractor to get the file name in the returned data
- Create a BeanShell post processor and save the file locally with the string extracted from the regularization as the file name
File download HTTP request:
Observe that the name of the downloaded file is in the return header:
Use regular to extract the current file name:
use BeanShell to save the returned body content to the local:
BeanShell code
import java.io.*;
//获取上个请求的返回数据
byte[] result = prev.getResponseData();
String f = vars.get("filename_01");
String file_name = "D:/a/".concat(f);
File file = new File(file_name);
FileOutputStream out = new FileOutputStream(file);
out.write(result);
out.close();