I have a post request where I have to send a gzip file as byte array. I have tried the following:
- Created a BeanShell preprocessor to convert the file to byte array with the following function(got this function from here) :
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));
- Added the parameter postData in HTTP Request Sampler under Parameter's tab as ${postData} . Also tried adding the parameter ${postData} in HTTP Request Sampler under BodyData tab.
But the file is not sent.
- I also tried sending the file by adding it under the tab "Send Files With the Request" section in HTTP request sampler with appropriate encoding.
But for all the cases I am getting the error :
:{"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)