title: Making POST request to a RESTful API with binary body using JMETER
body: <p>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.</p>
  
  <p>I use BeanShell Sampler to make binary data and put it into a variable</p>
  
  <pre><code>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);
  </code></pre>
  
  <p>Then HTTP Request, where in Body Data I put <code>${bytes}</code> 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 <code>bytes</code> is cast to string.
  The rather similar question is <a href="https://stackoverflow.com/questions/20219750/sending-http-requests-with-binary-body-using-jmeter">Sending HTTP requests with binary body using JMeter</a> 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?</p>
  
  <p>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.</p>