如何在 HTTP 请求中使用来自 Jmeter JDBC 请求的响应
这是我的情况:
我想这样做:
我有一个 MySQL 数据库中的 URL 列表,我想使用 HTTP 请求点击该列表,以查看响应是否为 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.
我已经这样做了:
- 添加并配置了 JDBC 配置元素.
- 添加并配置了 JDBC 请求采样器.基本上是一个选择语句,它返回一个包含 8 列的表.我为变量名"字段提供了 8 个逗号分隔的变量,以便可以使用这些变量名识别 JDBC 请求的结果.
- 创建了一个 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}/
我尝试了以下解决方案:
- 向 JDBC 请求添加保存对文件的响应"侦听器.这将创建一个.plain"类型的文件,而不是一个 CSV.如果它是一个 CSV,我可以通过创建一个 CSV 数据集配置来使用该 CSV 文件.所以这次尝试失败了.
- 我尝试在上述尝试中强制文件名始终使用C:JMETERTestdata.csv".但它最终会创建一个名为C:JMETERTestdata.csv1.plain"的新文件.这次尝试也失败了.
我尝试在 HTTP 请求的服务器名称字段中将 URL 列引用为 ${url_1}.有效.但现在的问题是,在结果树中,所有请求都只来自结果集的第一行的 URL.我看到这是因为上面 ${url_1} 中指定的行号_1".如果有人可以建议一种将_1"参数化为我可以循环的变量(可能使用计数器"元素)的方法,我可以使用它.我通过引用名称loopCounter"创建了一个计数器配置元素.并在 HTTP 请求的服务器名称字段中使用它:
- 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.
- I have tried forcing the file name in the above attempt to always use 'C:JMETERTestdata.csv'. But it ends up creating a new file named 'C:JMETERTestdata.csv1.plain'. This attempt failed too.
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.
相关文章