需要在jmeter中通过Webservice发送字节数组



我应该将图像转换为数组字节并将其与目的地位置一起发送到Webservice中。我用beanshell编写了这段代码

File file = new File("\PICS\k6.jpg"); 
FileInputStream in = new FileInputStream(file);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int i=0;
for (int i; (i = in.read(buffer)) != -1; ) 
{
bos.write(buffer, 0, i);
}
in.close();
 byte[] imageData = bos.toByteArray();
 bos.close();
 vars.put("imageData", new String(imageData));

我正面临这个错误-在文档的元素内容中发现一个无效的XML字符(Unicode: 0x0)。

变量"imageData"似乎是在ASCII,但如何发送它与请求。我需要数组对象

尝试在脚本顶部添加以下行:

import org.apache.commons.lang.StringEscapeUtils;

,并将最后一行修改如下:

vars.put("imageData", StringEscapeUtils.escapeXml(new String(imageData)));

UPD:端到端代码

import org.apache.commons.lang.StringEscapeUtils;
File file = new File("/home/glinius/test.html");
FileInputStream in = new FileInputStream(file);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];    
for (int i; (i = in.read(buffer)) != -1; ) {
    bos.write(buffer, 0, i);
}
in.close();
byte[] imageData = bos.toByteArray();
bos.close();
vars.put("imageData", StringEscapeUtils.escapeXml(new String(imageData)));

最新更新