向jMeter添加javascript函数
问题内容:
我正在尝试将JavaScript函数与jMeter测试计划一起使用。
它用于解码字符串。
function decode(str) {
var strtodecrypt = str.split("-");
var msglength = strtodecrypt.length;
decrypted_message = "";
for (var position = 0; position < msglength; position++) {
ascii_num_byte_to_decrypt = strtodecrypt[position];
ascii_num_byte_to_decrypt = ascii_num_byte_to_decrypt / 2;
ascii_num_byte_to_decrypt = ascii_num_byte_to_decrypt - 5;
decrypted_byte = String.fromCharCode(ascii_num_byte_to_decrypt);
decrypted_message += decrypted_byte;
}
return decrypted_message;
}
我尝试使用BSF Post处理器,但不知道我需要使用的确切语法是什么。我想使用此函数在一个HTTP请求中将jMeter变量作为参数发布。
编辑:
我目前正在BSF后处理器中使用以下脚本。userResponse
未在debub采样器中显示。我需要添加任何引用以使用String.fromCharCode(ascii_num_byte_to_decrypt)
吗?
var str="142";
var strtodecrypt = str.split("-");
var msglength = strtodecrypt.length;
decrypted_message = "";
for (var position = 0; position < msglength; position++) {
ascii_num_byte_to_decrypt = strtodecrypt[position];
ascii_num_byte_to_decrypt = ascii_num_byte_to_decrypt / 2;
ascii_num_byte_to_decrypt = ascii_num_byte_to_decrypt - 5;
decrypted_byte = String.fromCharCode(ascii_num_byte_to_decrypt);
decrypted_message += decrypted_byte;
}
vars.put("userResponse",decrypted_message);
问题答案: