How to decode base 64 format in jmeter?

送分小仙女□ 提交于 2019-12-07 01:53:28

Your solution is pretty good. However you can use Beanshell Post Processor and refer previous sampler response data as data (see JMeter Pre-defined Beanshell variables section)

import org.apache.commons.codec.binary.Base64;

vars.put("decoded_response", new String(Base64.decodeBase64(data)));

My current solution is:

import org.apache.commons.codec.binary.Base64;

log.info("Decoding base64 format");

String response = "b3JpZ2luYWwgU3RyaW5nIGJlZm9yZSBiYXNlNjQgZW5jb2RpbmcgaW4gSmF2YQ==";
byte[] decoded_response = Base64.decodeBase64(response);
log.info(new String(decoded_response));

Which is based on the solution provided by http://javarevisited.blogspot.pt/2012/02/how-to-encode-decode-string-in-java.html .

EDIT: Check Dmitri solution for more details.

Thanks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!