参考:https://stackoverflow.com/questions/33718462/how-to-post-gzip-request-with-apache-jmeter
Add HTTP Header Manager to your test plan and add at least the following headers:
- Content-Type: application/json
- Content-Encoding: gzip
Add Beanshell PreProcessor as a child of the request which you need to encode and add the following code to it's "Script" area:
import org.apache.commons.io.IOUtils; import java.util.zip.GZIPOutputStream; String bodyString = sampler.getArguments().getArgument(0).getValue(); byte [] requestBody = bodyString.getBytes(); ByteArrayOutputStream out = new ByteArrayOutputStream(requestBody.length); GZIPOutputStream gzip = new GZIPOutputStream(out); gzip.write(requestBody); gzip.close(); sampler.getArguments().getArgument(0).setValue(out.toString(0));It will get your request body, compress it and substitute on the fly so the request will be gzipped.
没有评论:
发表评论