1

每当尝试使用以下代码调用 JavaScript 函数时,我都会遇到异常:

断言失败消息:org.apache.jorphan.util.JMeterException:错误调用 bsh 方法:eval 源文件:内联评估:``vars.put("FinalData", decode64(PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiI . . . . '' :非法使用未定义变量、类或“无效”字面量

下面是 BSFPostProcess:

function decode64(input) {
     var output = "";
     var chr1, chr2, chr3 = "";
     var enc1, enc2, enc3, enc4 = "";
     var i = 0;

     // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
     var base64test = /[^A-Za-z0-9\+\/\=]/g;
     if (base64test.exec(input)) {
        alert("There were invalid base64 characters in the input text.\n" +
              "Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\n" +
              "Expect errors in decoding.");
     }
     input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

     do {
        enc1 = keyStr.indexOf(input.charAt(i++));
        enc2 = keyStr.indexOf(input.charAt(i++));
        enc3 = keyStr.indexOf(input.charAt(i++));
        enc4 = keyStr.indexOf(input.charAt(i++));

        chr1 = (enc1 << 2) | (enc2 >> 4);
        chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
        chr3 = ((enc3 & 3) << 6) | enc4;

        output = output + String.fromCharCode(chr1);

        if (enc3 != 64) {
           output = output + String.fromCharCode(chr2);
        }
        if (enc4 != 64) {
           output = output + String.fromCharCode(chr3);
        }

        chr1 = chr2 = chr3 = "";
        enc1 = enc2 = enc3 = enc4 = "";

     } while (i < input.length);
     return output;
}

我正在尝试使用以下代码在 BSF Assertion Sampler 下调用它。

vars.put("FinalData", decode64(${Data}));

或者

vars.put("FinalData", decode64(vars.get("Data")));

数据是可变的并存储值:

PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/Pgo8UmVxdWVzdFBhcnRzUmVzcG9uc2UgeG1sbnM9Imh0dHA6Ly9zZXJ2aWNlcy5teWNjY3BvcnRhbC5jb20vQWx0ZXJuYXRlUGFydFNvdXJjaW5nL0FsdGVybmF0ZVBhcnRTb3VyY2luZyI+CiAgICA8UGFydFJlcXVlc3RJZGVudGlmaWVyPjQwNTM4MTU8L1BhcnRSZXF1ZXN0SWRlbnRpZmllcj4KPC9SZXF1ZXN0UGFydHNSZXNwb25zZT4=

FinalData是预定义的变量。

4

1 回答 1

1

这不是预处理器的工作方式,您有两个选择:

无论如何,您将删除预处理器中的函数声明

于 2013-06-27T05:36:22.877 回答