【发布时间】:2014-05-11 14:04:37
【问题描述】:
我有一个发布请求,我必须将 gzip 文件作为字节数组发送。 我尝试了以下方法:
- 创建了一个 BeanShell 预处理器,使用以下函数将文件转换为字节数组(从此处获取此函数):
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
FileInputStream in = new FileInputStream("C:\Users\New\Desktop\Load_Testing");
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[] postData = bos.toByteArray();
bos.close();
vars.put("postData", new String(postData));
- 在参数选项卡下的 HTTP 请求采样器中添加参数 postData 作为 ${postData} 。还尝试在 BodyData 选项卡下的 HTTP Request Sampler 中添加参数 ${postData}。
但是文件没有发送。
- 我还尝试通过将文件添加到 HTTP 请求采样器的“使用请求发送文件”选项卡下并使用适当的编码来发送文件。
但对于所有情况,我都会收到错误消息:
:{"Result":"Error uploading data stream
The magic number in GZip header is not correct. Make sure you are passing in a GZip stream.
at System.IO.Compression.GZipDecoder.ReadHeader(InputBuffer input)
at System.IO.Compression.Inflater.Decode()
at System.IO.Compression.Inflater.Inflate(Byte[] bytes, Int32 offset, Int32 length)
at System.IO.Compression.DeflateStream.Read(Byte[] array, Int32 offset, Int32 count)
at System.IO.Compression.GZipStream.Read(Byte[] array, Int32 offset, Int32 count)
at System.IO.Stream.ReadByte()
at ServiceData.CompressionHelper.UnGZip(Byte[] input)
【问题讨论】: