I test a service with RESTful API, the methods receive POST requests with binary data. I use JMeter for testing. But I have troubles in making such requests with this tool.
I use BeanShell Sampler to make binary data and put it into a variable
import java.util.Base64;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.codec.binary.Base64;
String base64Str="Some string";
//Encode the string
byte[] bytes = Base64.encodeBase64(base64Str.getBytes());
vars.putObject("bytes", bytes);
Then HTTP Request, where in Body Data I put ${bytes}
in order to make it read the raw bytes from the variable and send it in a POST request. But then I get an exception "java.lang.ClassCastException: [B cannot be cast to java.lang.String", which means that in Body Data the given variable bytes
is cast to string.
The rather similar question is Sending HTTP requests with binary body using JMeter but there was done the same conclusion about string casting in the comments.
Maybe it can be done with sending a file with the request?
There's a plugin HTTP Raw Request, but I cannot find a way to send request to a concrete API method, while the plugin has only field for port (maybe write a method path right after port?), and I cannot find a way to pass bytes to it.