I'm calling a api serice that requires a http header with the hash value of the request body.
I'm trying to use a beanshell post processor in JMeter to automatically create the sha-256 hash of the request body. The hash value is right up until I introduce a line break in the request body (which is a pain as the JSON message spans several lines!)
I assume it's something to do with hidden characters however I can't work out what is going wrong! :(
When I compare the hash generated by JMeter to seperate Hash generator tools it is an exact match until there are line breaks, then JMeter is wrong.
Why is JMeter generating an incorrect hash when there are line breaks?
My code is:
[import org.apache.commons.httpclient.auth.DigestScheme; // necessary imports
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.jmeter.protocol.http.control.Header;
import org.apache.jmeter.services.FileServer;
import javax.xml.bind.DatatypeConverter;
import java.security.*;
String body = sampler.getArguments().getArgument(0).getValue();
String hash = DigestUtils.sha256Hex(body);
log.info(hash);