Yuval
Yuval

Reputation: 61

Sending HTTP requests with binary body using JMeter

I'm trying to send HTTP request with binary content using JMeter. In the documentation I found that I can send file with binary content. I think this is not a good solution for my need, since every request has its own binary content.

Here is an example of a client I wrote in Perl that demonstrates what I tried to accomplish:

$date_time = sprintf "%08X", time();
$BODY_TEMPLATE = "00${date_time}0015";
$body_len = (length (sprintf($BODY_TEMPLATE,0,0))) / 2;
# Here I set $TARGET & $HOST
$MSG_HEADER = "POST \/unil?URL=${TARGET} HTTP\/1.1\r\nHost: ${HOST}\r\ncontent-type:application/binary\r\ncontent-length: ${body_len}\r\n\r\n";
$body = pack ("H*", $BODY_TEMPLATE);
$message_to_send = $MSG_HEADER . $body;
# at this point I sent the entire message over a TCP socket I previously opened.

Any Ideas? Thanks, Yuval

Upvotes: 4

Views: 6554

Answers (1)

Dmitri T
Dmitri T

Reputation: 168002

It's possible using JMeter. I would recommend using

  1. Beanshell Pre-Processor to construct the body of your request and store it to JMeter Variable (you don't need to calculate content length as JMeter is smart enough to do it for you)
  2. Setting up a HTTP Sampler with "Body Data" generated in Beanshell Pre-Processor (at the end of body generation code you'll need to do something like vars.put("mybody",generatedbodystring);. In your HTTP Sampler you can refer mybody variable as either ${mybody} or ${__V(mybody)}
  3. Adding HTTP Header Manager to set Content-Type to "application/binary"

HTTP Header Manager and BeanShell Pre Processor must be children of your HTTP Request.

You can use Debug Sampler and View Results Tree Listener to inspect request/response details and data being sent.

Hope this helps.

Upvotes: 6

Related Questions