在JMeter中,我使用RegEx Extractor提取了響應中的base64編碼PDF。這一切都很好。JMeter無法正確解碼base64 - 結果爲空白PDF
然後我需要解碼的是base64編碼的文件,並將其寫入到一個文件,我正與一個BeanShell的後置處理器以下做:
import org.apache.commons.io.FileUtils;
import org.apache.commons.codec.binary.Base64;
// Set the response variable
String response = vars.get("documentText");
// Remove the carriage return hex code and condense to single string
String encodedFile = response.replace("
","").replaceAll("[\n]+","");
// Decode the encoded string
vars.put("decodedFile",new String(Base64.decodeBase64(encodedFile)));
// Write out the decoded file
Output = vars.get("decodedFile");
f = new FileOutputStream("C:\\Users\\user\\Desktop\\decodedFile.pdf");
p = new PrintStream(f);
this.interpreter.setOut(p);
print(Output);
p.flush();
f.close();
我的問題是,文件獲取解碼和寫出將以空白PDF格式打開。
在解決這個問題時,我用JMeter編碼的字符串寫出了一個文件,然後使用this base64工具手動解碼。當我手動解碼文件時,它按預期打開。
然後我比較了JMeter生成的文件和我使用該工具解碼的文件的文本,並注意到JMeter生成的文件包含隨機文件?的整個
我認爲這必須是罪魁禍首,但是,我不知道是什麼導致這些顯示或如何解決它。
您對服務器響應低落的期望是正確的。它包含一個多行(apporx 7,500行)base64編碼的PDF格式,每行結尾有回車十六進制代碼,這就是爲什麼我正在做我正在做的事情。您的優化代碼效果很好! –