URL encode variable in Jmeter

微笑、不失礼 提交于 2020-01-28 05:39:06

问题


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:


JMeter as of version 2.10 now includes a urlencode function.

${__urlencode(${token})}

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




回答2:


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



回答3:


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




回答4:


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



来源:https://stackoverflow.com/questions/14593183/url-encode-variable-in-jmeter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!