如何在HTTP请求中使用来自Jmeter JDBC请求的响应 [英] How to use responses from a Jmeter JDBC Request in a HTTP Request

查看:125
本文介绍了如何在HTTP请求中使用来自Jmeter JDBC请求的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的情况:

我要这样做:

我有一个MySQL数据库中的URL列表,我想使用HTTP请求来访问该URL,以查看响应是否为404的HTTP状态代码.

I have a list of URLs in a MySQL database which I want to hit using a HTTP Request to see if the response is a HTTP Status code of 404 or not.

我已这样做:

  1. 添加并配置了JDBC Config元素.
  2. 添加并配置了JDBC请求采样器.基本上,一条select语句返回一个包含8列的表.我为变量名称"字段提供了8个逗号分隔的变量,以便可以使用这些变量名来标识JDBC请求的结果.
  3. 创建了一个HTTP请求采样器,该服务器使用服务器名称或IP"字段中的变量$ {url}之一.

尽管JDBC请求可以正常工作并返回包含一堆行的表,但这是HTTP请求采样器从不从JDBC请求结果中提取变量的问题. HTTP请求在查看结果树"中如下所示:

Though the JDBC request works flawlessly and returns a table with a bunch of rows, the problem with this is that the HTTP Request Sampler never picks up the variable from the JDBC Request result. The HTTP Request looks like this in the 'View Results Tree':

GET http://${url}/

我已经尝试了以下解决方案:

  1. 将将响应保存到文件"侦听器添加到JDBC请求.这将创建类型为".plain"而不是CSV的文件.如果是CSV,我可以通过创建CSV数据集配置来利用该CSV文件.因此,此尝试失败.
  2. 在上面的尝试中,我尝试强制文件名始终使用'C:\ JMETERTest \ data.csv'.但是最终创建了一个名为"C:\ JMETERTest \ data.csv1.plain"的新文件.这次尝试也失败了.
  3. 我尝试在"HTTP请求的服务器名称"字段中将URL列引用为$ {url_1}.有效.但是现在的问题是,在结果树中,所有请求都只针对结果集第一行中的URL.我看到这是由于在上面$ {url_1}中指定了行号"_1".如果有人可以建议将"_1"参数化为我可以循环通过的变量(可能使用"Counter"元素)的方法,则可以使用此方法.我通过引用名称"loopCounter"创建了一个Counter Config元素.并在HTTP请求的服务器名称"字段中使用了它:

  1. Add 'Save Responses to a File' listener to the JDBC Request. This creates a file of type '.plain' and not a CSV. Had it been a CSV, I could have utilized that CSV file by creating a CSV Data Set Config. So this attempt failed.
  2. I have tried forcing the file name in the above attempt to always use 'C:\JMETERTest\data.csv'. But it ends up creating a new file named 'C:\JMETERTest\data.csv1.plain'. This attempt failed too.
  3. I tried to reference the URL column as ${url_1} in the HTTP Request's Server Name field. It worked. But the problem now is that in the results tree, all the requests are going for the the URL from only the first row of the result set. I see that this is because of the row number '_1' specified in the ${url_1} above. I can use this if someone can suggest a way to parameterize the '_1' into a variable that I can loop through (probably using a 'Counter' element). I created a Counter Config Element by the Reference Name 'loopCounter'. And used this in the Server Name field of the HTTP Request:

$ {url _("$ {loopCounter}")}

${url_("${loopCounter}")}

但是现在我的HTTP请求看起来更糟了:

But now my HTTP Requests look lamer:

GET http://${url_("${loopCounter}")}/

这也不起作用.

仅当我可以解析行号的参数设置时,解决方案3才看起来更可行. 我也愿意接受JMeter插件的建议. 我们将继续尝试的其他任何内容.

Solution 3 looks more doable to be only if I could resolve the parameterization of the row number. I am open to JMeter Plugin suggestions too. I will update anything else that I try as we go on.

P.S.如果我的问题仍然不清楚,请告诉我.

推荐答案

您是否尝试过将HTTP采样器包装在ForEach控制器(父代)中,该控制器的变量是从JDBC采样器获得的URL变量?

Have you tried wrapping the HTTP sampler in a ForEach controller (parent) where the variable for the controller is the URL variable obtained from the JDBC sampler?

此外,ForEach中的输出变量将是您现在在HTTP采样器中使用的变量.

Also, the output variable in the ForEach will be the variable you now use in the HTTP sampler.

这样,它将从索引的开头到结尾遍历每个变量,并每次运行一次采样器.

That way it will iterate through each variable from the beginning of the index to the end and run the sampler once each time.

这篇关于如何在HTTP请求中使用来自Jmeter JDBC请求的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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