状态码 302 重定向前的 JMeter 响应 headers 值

JMeter reponse headers values before redirection on status code 302

我正在使用 JMeter 对 API 执行负载测试。为此,我将 oauth link 称为 returns headers 中的代码,我将其用于进一步测试。但是 link 重定向到另一个 link,当返回状态代码为 302 的响应时,我无法捕获响应 headers 的值。我该怎么做。

您有 2 个选择:

  1. 不允许重定向 HTTP 请求。只需取消选中 HTTP 采样器中的 "Follow Redirects" 复选框:

    这样你就可以正常处理这个请求了。缺点当然是您需要添加第二个请求,它将带您到通常自动重定向到的 link。

  2. 大多数 post-处理器允许您从主样本或子样本或两者中提取值。因此,像以前一样遵循重定向,但更改 Post-Processor 以从子样本中提取值。例如正则表达式提取器:

如果你的情况是这样的:

您仍然可以通过修改正则表达式提取器范围从后一个示例结果中提取动态值

根据documentation

Apply to:

This is for use with samplers that can generate sub-samples, e.g. HTTP Sampler with embedded resources, Mail Reader or samples generated by the Transaction Controller.

  • Main sample only - only applies to the main sample

  • Sub-samples only - only applies to the sub-samples

  • Main sample and sub-samples - applies to both.

  • JMeter Variable - assertion is to be applied to the contents of the named variable

默认情况下正则表达式提取器正在查找 Main sample only,在上面的示例中它是 HTTP Request,如果您要查找的数据存储在 sub-samples 之一更改正则表达式提取器的范围以查看 sub-results 就足够了: