首页 > 解决方案 > Jmeter 中的 Gzipped 肥皂请求

问题描述

是否可以发送 gzipped 肥皂请求?

我添加了一个带有以下标头的 HTTP 标头管理器:

Content-Type: application/soap+xml; charset=Utf-8
Content-Encoding: gzip 

我添加了一个 Beanshell PreProcessor 作为需要编码的请求的子项,并定义了以下脚本:

import org.apache.commons.io.IOUtils;
import java.util.zip.GZIPOutputStream;

// This only works for the HTTP Request, not Soap Request.
// String bodyString = sampler.getArguments().getArgument(0).getValue();
String bodyString = ctx.getCurrentSampler().getXmlData();

byte [] requestBody = bodyString.getBytes();

ByteArrayOutputStream out = new ByteArrayOutputStream(requestBody.length);
GZIPOutputStream gzip = new GZIPOutputStream(out);
gzip.write(requestBody);
gzip.close();

// This only works for the HTTP Request, not Soap Request.
// sampler.getArguments().getArgument(0).setValue(out.toString(0));
ctx.getCurrentSampler().setXmlData(???);

我的问题是最后一行,我该如何设置 xmlData?

Jmeter 3.1版

标签: soaprequestjmetergzip

解决方案


  1. 已弃用的 SOAP/XML-RPC 采样器替换为HTTP 请求采样器
  2. 升级到JMeter 5.0 (或JMeter 下载页面提供的最新版本)
  3. Beanshell 切换到 Groovy
  4. 用于sampler.getArguments().getArgument(0).setValue(out.toString(0));生成请求正文。

推荐阅读