开发者

Sending a JSON POST request with BSF Preprocessor

开发者 https://www.devze.com 2023-04-05 22:44 出处:网络
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 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开发者_C百科 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.


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.


set property on your sampler "HTTPArgument.always_encode" to false this should disable argument encoding

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号