如何在Jmeter中的http请求中发送字节数组 [英] How to Send Byte Array in http request in Jmeter

查看:1283
本文介绍了如何在Jmeter中的http请求中发送字节数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用j meter进行负载测试,我必须通过http请求调用上传的Image API,并实现这一点,我必须将图像转换为压缩字节数组,通过http请求将其作为发布数据发送出去。

任何人都可以通过jmeter来帮助我。



您的帮助真的很值得赞赏。

解决方案

有几种选择可以继续:


  1. 您可以使用 HTTP原始请求取样器(可通过 JMeter插件站点),它可以让你完全控制你发送的内容,方式和位置。

  2. 这就是应该如何根据 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:

  1. You can use HTTP Raw Request Sampler (available through JMeter Plugins site) which gives you full control on what, how and where you send.

  2. 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.

  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆