Reputation: 1021
I've captured some HTTP traffic using fiddler but both the request and response have a combination of plain and garbled text.
Example request in raw format:
The developer advised the request is being base64 encoded first and then compressed using deflate. Likewise the response needs to be base64 decoded and then uncompressed.
How can I handle this in JMeter?
Upvotes: 0
Views: 3435
Reputation: 168042
You can decode/uncompress the response using JSR223 PostProcessor and Groovy language like:
prev.setResponseData(new java.util.zip.GZIPInputStream(new ByteArrayInputStream(prev.getResponseDataAsString().decodeBase64())).getBytes())
prev
stands for HTTPSampleResult class instance providing access to all its functions and properties in current context.
Similarly you can use sampler
shorthand which is for HTTPSamplerProxy in JSR223 PreProcessor to compress/encode the request.
Check out Top 8 JMeter Java Classes You Should Be Using with Groovy article for more information on using JMeter API components in Groovy scripts
Upvotes: 0
Reputation: 1999
Check your header contains the below values or include that:-
Header Value: gzip,deflate
Normally, it should be captured if used jmeter proxy recording.
Ref:-https://octoperf.com/blog/2017/10/24/enable-gzip-compression-jmeter/
For decoding in JSR223 sampler;-
import org.apache.commons.codec.binary.Base64;
vars.put("decoded_response", new String(Base64.decodeBase64(data)));
You need to pass the data field or try the solution with custom plugin.
Ref:-How to decode base 64 format in jmeter?
Hope this helps.
Upvotes: 0
Reputation: 664
Install the Jmeter Plugin Custom JMeter Functions plugin, It provides base64Encode and base64Decode functions which can be used for your use case.
${__base64Encode(test string)}
${__base64Decode(dGVzdCBzdHJpbmc=)}
Upvotes: 1