سؤال

Does anyone know a solution to decode a base 64 format string in JMeter?

I have to decode the a response, but i don't want to reinvent the wheel...

Do i have to write the code by myself (hope not)?

Thanks

هل كانت مفيدة؟

المحلول 2

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

نصائح أخرى

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)));
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top