Reputation: 397
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.
Upvotes: 2
Views: 3147
Reputation: 397
I managed to make a POST request with binary body data using HTTP Request. In order to do it I added an entry to "Send files with the request" and filled only file path field (without parameter name and MIME type). JMeter reads the given file and in this case sends its bytes as in the body of a POST request.
The answer was found here https://qnalist.com/questions/698175/does-jmeter-support-sending-arbitrary-binary-data-in-the-body-of-a-post and led to manual http://jmeter.apache.org/usermanual/component_reference.html#HTTP_Request
Upvotes: 5