如何在Jmeter中的http请求中发送字节数组 [英] How to Send Byte Array in http request in Jmeter
问题描述
任何人都可以通过jmeter来帮助我。
您的帮助真的很值得赞赏。
有几种选择可以继续:
- 这就是应该如何根据 RFC-1867 上传文件的方式。如果您的用例是特定的并且以上都不适用,您可以始终使用JMeter脚本扩展。例如,如果您将一个 Beanshell预处理器添加到您的HTTP请求它执行文件上传类似于:
FileInputStream in = new FileInputStream(/ home / glinius / 401.png);
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,new String(imageData));
您可以将 $ {imageData}
参数。
I`m using j meter for load testing where I have to call upload Image API through http request and to achieve this I have to convert an image into compressed byte array to send out it as post data through http request.
Can anyone help me how it would be possible through jmeter.
Your help would really be appreciated.
There are several options on how you can proceed:
You can use HTTP Raw Request Sampler (available through JMeter Plugins site) which gives you full control on what, how and where you send.
Have you tried enabling
Use multipart/form-data for POST
for HTTP Request Sampler? This is how files should be uploaded as per RFC-1867.If your use case is specific and none of the above is applicable, you can always use JMeter Scripting extensions. For example if you add a Beanshell Pre Processor to your HTTP Request which performs file upload with something like:
FileInputStream in = new FileInputStream("/home/glinius/401.png"); 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", new String(imageData));
You'll be able to add ${imageData}
parameter in your POST request.
这篇关于如何在Jmeter中的http请求中发送字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!