使用JMeter发送具有二进制主体的HTTP请求 [英] Sending HTTP requests with binary body using JMeter

查看:548
本文介绍了使用JMeter发送具有二进制主体的HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JMeter发送具有二进制内容的HTTP请求. 在文档中,我发现我可以发送带有二进制内容的文件.我认为这不是我需要的解决方案,因为每个请求都有自己的二进制内容.

I'm trying to send HTTP request with binary content using JMeter. In the documentation I found that I can send file with binary content. I think this is not a good solution for my need, since every request has its own binary content.

以下是我在Perl中编写的一个客户端示例,该示例演示了我试图实现的目标:

Here is an example of a client I wrote in Perl that demonstrates what I tried to accomplish:

$date_time = sprintf "%08X", time();
$BODY_TEMPLATE = "00${date_time}0015";
$body_len = (length (sprintf($BODY_TEMPLATE,0,0))) / 2;
# Here I set $TARGET & $HOST
$MSG_HEADER = "POST \/unil?URL=${TARGET} HTTP\/1.1\r\nHost: ${HOST}\r\ncontent-type:application/binary\r\ncontent-length: ${body_len}\r\n\r\n";
$body = pack ("H*", $BODY_TEMPLATE);
$message_to_send = $MSG_HEADER . $body;
# at this point I sent the entire message over a TCP socket I previously opened.

有什么想法吗? 谢谢, 尤瓦尔

Any Ideas? Thanks, Yuval

推荐答案

可以使用JMeter.我建议使用

It's possible using JMeter. I would recommend using

  1. Beanshell预处理器来构造请求的正文并将其存储到JMeter变量(您无需计算内容长度,因为JMeter足够聪明,可以为您完成此操作)
  2. 使用Beanshell预处理器中生成的正文数据"设置HTTP采样器(在主体生成代码的最后,您需要执行类似vars.put("mybody",generatedbodystring);的操作.在HTTP采样器中,您可以引用mybody变量${mybody}${__V(mybody)}
  3. 添加 HTTP标头管理器,将Content-Type设置为"application /binary"
  1. Beanshell Pre-Processor to construct the body of your request and store it to JMeter Variable (you don't need to calculate content length as JMeter is smart enough to do it for you)
  2. Setting up a HTTP Sampler with "Body Data" generated in Beanshell Pre-Processor (at the end of body generation code you'll need to do something like vars.put("mybody",generatedbodystring);. In your HTTP Sampler you can refer mybody variable as either ${mybody} or ${__V(mybody)}
  3. Adding HTTP Header Manager to set Content-Type to "application/binary"

HTTP标头管理器和BeanShell预处理器必须是HTTP请求的子代.

HTTP Header Manager and BeanShell Pre Processor must be children of your HTTP Request.

您可以使用调试采样器"和查看结果树侦听器"来检查请求/响应详细信息以及正在发送的数据.

You can use Debug Sampler and View Results Tree Listener to inspect request/response details and data being sent.

希望这会有所帮助.

这篇关于使用JMeter发送具有二进制主体的HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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