Url Encode Variable in Jmeter

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?

1

4 Answers

JMeter as of version 2.10 now includes a urlencode function.

${__urlencode(${token})}

See

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

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest