Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending a JSON POST request with BSF Preprocessor

I am working with JMeter to write some performance tests. One of the things that I need to do is to construct a huge json request dynamically and send it as POST request paylod. Using BSF preprocessor, I am able to modify the payload dynamically however my javascript string is being encoded, while I want to send it without being encoded.

I am not sure how BSF preprocessor can stop it from being encoded. The command I currently use to change my POST request payload is as follows:

var jsonData = '[{"item":"value","something":"everything"}]';
sampler.addArgument("",jsonData);

I would really appreciate if you can point me to some examples which clearly explain how bsf preprocessors are expected to be used.

Any pointers to skip the encoding will also be appreciated.

like image 918
Priyank Avatar asked Sep 20 '11 11:09

Priyank


1 Answers

Since JMeter 2.6 you can use the RAW request pane using Post Body tab.

So your solution is to do the following:

  1. In BSF Sampler, put you JSON in a variable:

    var jsonData = '[{"item":"value","something":"everything"}]';
    vars.putObject("jsonData",jsonData);
  2. In Post Body, put:

    ${jsonData}

Another option using your method is to put in BSFPreProcessor using Beanshell language (not javascript):

import org.apache.jmeter.protocol.http.util.HTTPArgument;
String jsonData = "[{\"item\":\"value\",\"something\":\"everything\"}]";
HTTPArgument arg =new HTTPArgument("", jsonData, null, true);
arg.setAlwaysEncoded(false);
sampler.getArguments().addArgument(arg);

Regards

Philippe M.

like image 147
UBIK LOAD PACK Avatar answered Sep 28 '22 16:09

UBIK LOAD PACK