我遇到Jmeter问题,使用BeanShell PreProcessor对输入文件进行编码,然后将编码文件包含在“请求发送文件”中。
Jmeter设置
BeanShell PreProcessor
import org.apache.commons.io.FileUtils;
import org.apache.commons.codec.binary.Base64;
String file1 = FileUtils.readFileToString(new File("D:/File/test.txt"),"UTF-8");
vars.put("file1",new String(Base64.encodeBase64(file.getBytes("UTF-8"))));
错误消息
java.io.FileNotFoundException: ${file1} (The system cannot find the file specified)
答案 0 :(得分:1)
如果您尝试执行以下操作:
您的Beanshell代码应如下所示:
String file1 = FileUtils.readFileToString(new File("D:/File/test.txt"), "UTF-8");
FileUtils.write(new File("D:/File/testbase64.txt"),new String(Base64.encodeBase64(file1.getBytes("UTF-8"))));
vars.put("file1","D:/File/testbase64.txt");
您的代码段是
file
JMeter变量file.getBytes()
中的拼写错误应更改为file1.getBytes()
有关Apache JMeter中bsh脚本的更多信息,请参阅How to use BeanShell: JMeter's favorite built-in component指南。