jmeterurlencodejsr223

I want to send the data that has been url encoding in Jmeter


I want to send a data that has been encryption. So, I used JSR223 Sampler.

---skip---

def encrypted = Crypto.encrypt("AES/CBC/PKCS5Padding", "{"MY_SENTENCE"}", Crypto.generateSecretKey(), Crypto.generateIv())

vars.put("enc_data", encrypted);


Body Data in HTTP Request.


{ "data": "${enc_data}" }


In Results Tree Request Body data was not url-encoding.

I want to send a data of url encoding, what should I do? I don't know that.

I wrote Body Data in HTTP Request. So, I can't click the Parameters.

And I added Content encoding (UTF-8) it was not working too.


Solution

  • Either use __urlencode() function in the Body Data tab directly:

    { "data": "${__urlencode(${enc_data})}" }
    

    JMeter Functions can be placed anywhere in the test plan and they're evaluated in the place where they're present so your ${enc_data} variable will be url-encoded in the runtime. See Apache JMeter Functions - An Introduction article for more information on JMeter Functions concept.

    or call URLEncoder.encode() function in your Groovy script directly:

    vars.put("enc_data", URLEncoder.encode(encrypted,"UTF-8"));