16

I need to encode a variable in Jmeter, but it isn't a parameter. For example:

URL path: /folder/guest/id;token=${token}/profile?details=yes

I want to encode the ${token} variable, and only the token variable. I know that you can select encode in the parameters section, but this isn't a parameter.

Does anyone know how to do this?

BlackHatSamurai
  • 23,275
  • 22
  • 95
  • 156
  • In my case, ? is getting encoded to "\udd03" like this. Could you please suggest any workaround ? – PAA Jun 04 '19 at 13:59

4 Answers4

30

JMeter as of version 2.10 now includes a urlencode function.

${__urlencode(${token})}

See http://jmeter.apache.org/usermanual/functions.html

Irate Pirate
  • 590
  • 1
  • 6
  • 11
8

The best way I found to do this was to use a JavaScript function:

${__javaScript(encodeURIComponent('${token}'))}

So the request would be:

/folder/guest/id;token= ${__javaScript(encodeURIComponent('${token}'))}/profile?details=yes
BlackHatSamurai
  • 23,275
  • 22
  • 95
  • 156
6

If you are using JMeter GUI -- HTTP Request, you can check the encode option:

enter image description here

dvorak4tzx
  • 493
  • 7
  • 8
0

__urlencode function works fine. It is just we need to put token variable in
quotes. i.e. ${__urlencode('${token}')}

bodhi
  • 203
  • 3
  • 14